I'm using the official docs here: 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;
}
I'm using the official docs here: https://docs.woocommerce/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;
}
Share
Improve this question
asked Oct 24, 2018 at 20:45
NotaGuruAtAllNotaGuruAtAll
1011 bronze badge
1 Answer
Reset to default 0You 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;
}