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.
I think you need to return the value, not echo:
However, i think this will also overwrite any other discounts that have been applied.