I want to add discount by click on custom button in Add-to-cart page.
-
Hello everyone, I want to add discount by click on custom button in Add-to-cart page. But it’s not happening. How can I do that?? Below is my code that I have added in theme functions.php:
function add_content(){ if(isset($_POST['takeway'])) { // Call Recalculate function add_action( 'woocommerce_after_calculate_totals', 'woocommerce_after_calculate_totals', 30 ); } ?> <form method="post"> <input type="submit" name="takeway" value="Takeway"/> </form> <?php } add_action('woocommerce_cart_coupon', 'add_content'); // Recalculate Function function woocommerce_after_calculate_totals( $cart ) { global $woocommerce; $subtotal = $woocommerce->cart->get_subtotal(); $discount = 40/100; $cart->total = $subtotal*$discount; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘I want to add discount by click on custom button in Add-to-cart page.’ is closed to new replies.