Last active
August 17, 2018 11:58
-
-
Save raiden808/ae7bcb3fb7c6f49867ea521f1991f82b to your computer and use it in GitHub Desktop.
Add tax on cart total depending on category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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