Apply zero tax to Australian orders over $1000 in Woocommerce

Viewed 96

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.

1 Answers

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.

Related