Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add tax on cart total depending on category
function woocommerce_custom_tax() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
$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
You can’t perform that action at this time.