Home How do I apply Cart Discount Before Tax in woocommerce
Reply: 1

How do I apply Cart Discount Before Tax in woocommerce

Leroy Mikenzi
1#
Leroy Mikenzi Published in 2014-02-26 07:15:39Z

I have being trying to apply cart discount before tax usgin my custom Woocommerce Plugin. But it is not getting applied using the action hook woocommerce_cart_discounts_before_tax in my custom plugin file.

Here is the code from my custom plugin file.

public function custom_discount(){
                global $woocommerce;
                $abc = woocommerce_price(5);
                echo $abc;
}

and the action hook

if(!empty($_POST['apply_discount_woo'])){
                    add_action( 'woocommerce_cart_discounts_before_tax', array(&$this,'custom_discount'));
                }

I get the following screen

The screenshot shows $5 above the subtotal but doesn't get applied to the cart and shows the wrong total.

James Kemp
2#
James Kemp Reply to 2014-03-26 16:14:25Z

I think you need to return the value, not echo:

public function custom_discount(){
    global $woocommerce;
    $abc = woocommerce_price(5);
    return $abc;
}

However, i think this will also overwrite any other discounts that have been applied.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.325942 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO