0

I'm using the official docs here: https://docs.woocommerce.com/document/setting-up-taxes-in-woocommerce and their snippet below to create a threshold trigger so that orders below $110 are not taxed. The problem is, WC()->cart->subtotal seems to always be 0 when this filter fires even with items in cart. Any ideas / insight?

add_filter( 'woocommerce_product_tax_class', 'big_apple_get_tax_class', 1, 2 );

function big_apple_get_tax_class( $tax_class, $product ) {
    if ( WC()->cart->subtotal <= 110 )
        $tax_class = 'Zero Rate';

    return $tax_class;
}

1 Answer 1

0

You should get the subtotal like this:

global $woocommerce;
$cart_subtotal = $woocommerce->cart->get_cart_subtotal();

From here. So you will can do something like this:

add_filter( 'woocommerce_product_tax_class', 'big_apple_get_tax_class', 1, 2 );

function big_apple_get_tax_class( $tax_class, $product ) {
    global $woocommerce;
    $cart_subtotal = $woocommerce->cart->get_cart_subtotal();
    if ( $cart_subtotal <= 110 )
        $tax_class = 'Zero Rate';

    return $tax_class;
}
1
  • Still returns zero, also get_cart_subtotal returns the markup in addition to the price. Commented Oct 25, 2018 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.