I want to calculate tax based on the entire cart subtotals. So in my case, if the subtotal is < 1000
, the Tax need to be 5%
If the subtotal is >=1000
, the Tax needs to be 12%
I am having two classes Reduced rate - 5%
, Standard - 12%
add_action( 'woocommerce_product_variation_get_tax_class', 'wp_check_gst', 1, 2 );
function wp_check_gst( $tax_class, $product )
{
$subtotal = 0;
foreach ( WC()->cart->get_cart() as $cart_item ) {
$subtotal += $cart_item[ 'data' ]->get_price( 'edit' ) * $cart_item[ 'quantity' ];
}
if ( $subtotal >= 1000 )
{
$tax_class = "Standard";
}
if ( $subtotal < 1000 )
{
$tax_class = "Reduced rate";
}
return $tax_class;
}
I use this above code, which seems to be not working?? What am I missing?