Skip to content

Instantly share code, notes, and snippets.

@aadityajs
Forked from mikejolley/gist:5568708
Created January 3, 2014 10:14
Show Gist options
  • Save aadityajs/8235774 to your computer and use it in GitHub Desktop.
Save aadityajs/8235774 to your computer and use it in GitHub Desktop.
Apply tax based on subtotal
<?php
add_filter( 'woocommerce_product_tax_class', 'big_apple_get_tax_class', 1, 2 );
function big_apple_get_tax_class( $tax_class, $product ) {
global $woocommerce;
if ( $woocommerce->cart->subtotal <= 110 )
$tax_class = 'Zero Rate';
return $tax_class;
}
?>
@eugenioheer
Copy link

// Changes is made By Manish Jain <Manishjain@gmail.com>
		// Added the contion for Tax below/above the 110
		$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', round( $this->cart_contents_total +  $this->fee_total, $this->dp ), $this ) );

		if($this->total > 110){
			$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', round( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total, $this->dp ), $this ) );
		}else{
			$this->taxes  = 0;
		}
		// Changes is made By Manish Jain <Manishjain@gmail.com>

Added in wp-content/plugins/woocommerce/includes/class-wc-cart.php

@eugenioheer
Copy link

This worked for me

@sachin447
Copy link

Hi,

your formula is working for me but I also want to set state too along with subtotal. How I can do this ? I want to use tax class as Zero if customer is from New York and subtotal is <= 110.

Any help ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment