2

Due to the new Australian gst rules I need to be able to charge standard gst on sales to Australian customers with a value less than $1000, and zero rated gst on sales above $1000 (as these are handled by AU customs).

I would like to use Set different Tax rates conditionally based on cart item prices in Woocommerce answer code that can be adapted to my needs, targeting orders with an Australian shipping address.

If anyone has any idea how I can do this please let me know.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
JapeNZ
  • 75
  • 10

1 Answers1

1

Using a similar code to the linked answer, you can try the following that will target Australian customers which cart subtotal is up to $1000:

add_action( 'woocommerce_before_calculate_totals', 'apply_conditionally_zero_tax_rate', 10, 1 );
function apply_conditionally_zero_tax_rate( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
        return;

    // Targeting australia billing country only
    if ( WC()->customer->get_billing_country() !== 'AU' )
        return;

    $defined_amount = 1000;
    $subtotal = 0;

    // Loop through cart items (1st loop - get cart subtotal)
    foreach ( $cart->get_cart() as $cart_item ) {
        $subtotal += $cart_item['line_total'];
    }

    // Targeting cart subtotal up to the "defined amount"
    if ( $subtotal < $defined_amount )
        return;

    // Loop through cart items (2nd loop - Change tax rate)
    foreach ( $cart->get_cart() as $cart_item ) {
        $cart_item['data']->set_tax_class( 'zero-rate' );
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Hi LoicTheAztec, thank you so much for looking at this for me :) Unfortunately I can't seem to get it to work. When a cart has an AU billing address the tax changes to 15% (NZ GST). I'm assuming this is due to me having a couple of zero rated tax classes so perhaps it's taking on the default instead? The AU zero rated tax class is listed as , how would I call this specific class instead of 'set_tax_class( 'zero-rate' );'? I've tried a couple of things but have so far failed horribly haha! Thanks for your help! – JapeNZ Jan 19 '19 at 03:14