## woocommerce offtopic – adding surcharge based on subcategory and category

Question

function woocommerce_custom_surcharge() {
global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;$percentage = 0.3; // Add your percentage here
$surcharge = ($woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) *$percentage;
$woocommerce->cart->add_fee( 'Surcharge',$surcharge, true, '' );

}

this is all good but I want to add a surcharge based on the product category and subcategory too. is there any option to that ?

wp : 5.8
php 8.0.7

0
1 year 2021-07-25T16:11:31-05:00 0 Answers 0 views 0