User Tools

Site Tools


start:website:source

This is an old revision of the document!


/**
 * @snippet       Add tax for dealers shipping to California
 * @author        André Le Comte
 */ 
function add_CA_cart_tax() {
global $woocommerce;
$taxable_states = array('CA');
$taxable_roles = array('customer');
$user_data = get_userdata( get_current_user_id() );
$user_roles = $user_data->roles;
if( in_array('customer', $user_roles) && in_array( WC()->customer->shipping_state, $taxable_states) ) {
 $surcharge = 0.083 * WC()->cart->subtotal; // 8.3% tax based on shipping location
 $woocommerce->cart->add_fee( __('California tax', 'woocommerce'), $surcharge );
}
}
 
add_action( 'woocommerce_cart_calculate_fees', 'add_CA_cart_tax' );
start/website/source.1476211172.txt.gz · Last modified: 2016/10/11 11:39 by andre