Skip to content

Instantly share code, notes, and snippets.

@raiden808
Last active August 17, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raiden808/ae7bcb3fb7c6f49867ea521f1991f82b to your computer and use it in GitHub Desktop.
Save raiden808/ae7bcb3fb7c6f49867ea521f1991f82b to your computer and use it in GitHub Desktop.
Add tax on cart total depending on category
function woocommerce_custom_tax() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$flowers_in_cart = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
//check if there's a product under flowers category
if ( has_term( 'flowers', 'product_cat', $cart_item['product_id'] )) {
$urns_in_cart = true;
}
}
if($flowers_in_cart == true){
$woocommerce->cart->add_fee( 'Service Fee', 9.95);
}
}
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_tax' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment