$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>WooCommerce Tax Filter Not Working|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WooCommerce Tax Filter Not Working

matteradmin10PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 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;
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far