• Resolved jorpdesigns

    (@jorpdesigns)


    Hello,

    I created a “Fixed basket discount” coupon with the hope of removing 5 pounds from order total if order is above 45 pounds. Unfortunately tax is calculated on this discount leading the discount to get as high as 60 pounds on some products for example. I understand this is because prices were set to be added exclusive of tax and this affects basket discounts too for some reason.

    I also tried applying the discount programmatically as shown in the code below but no luck.

    add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_total', 20, 1 );
    function discount_based_on_total( $cart ) {
    	global $woocommerce;
    
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
    
        $total = $cart->cart_contents_total;
    
        if( $total > 45 )
            $discount = 5;
    
    	WC()->cart->add_fee( 'Discount', -$discount, false );
    }

    Is there a way out please?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jorpdesigns

    (@jorpdesigns)

    Just wanna see if you got this?

    Plugin Support Damianne P (a11n)

    (@drwpcom)

    Hi @jorpdesigns. The behavior that you’ve noticing with tax being added to the value of a coupon with prices set to exclude tax in the store is expected behavior. You can read more about it here.

    This thread has been open for a while and it looks like no one was able to help with your code, so I’m going to go ahead and resolve the post.

    If you haven’t been able to customize a solution and would like developer assistance with this, I recommend contacting one of the services on our Customizations page. You can also join the WooCommerce Community Slack to engage with developers who may be able to help.

    Johnny

    (@johnexposureninja)

    Here’s a fix incase someone needs help:

    add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_total' );
    function discount_based_on_total( $cart ) {
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
    
        $total = $cart->subtotal;
    
        if( $total > 45 ) {
            $discount = 5;
            WC()->cart->add_fee( 'Discount', -$discount, false );
        }
    }
    
    add_filter( 'woocommerce_cart_totals_get_fees_from_cart_taxes', 'exlude_cart_fees_taxes', 10, 3 );
    function exlude_cart_fees_taxes( $taxes, $fee, $cart ) {
    	return array();
    }
    • This reply was modified 4 years ago by Johnny.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Tax being added to discounts’ is closed to new replies.