In Woocommerce How to add apply additional charge to specific Category Products or Specific Product added in Cart ?
In following example we used woocommerce_cart_calculate_fees Woocommerce action and added Additional Fees (5 Percent) for Only Products which belong to specific Category ( Category ID 1025).
By following code if Customer will purchase any Products which belong to Category ID 1025 than additional charge (5 Percent) will be applied and showing on Checkout page and Cart Page.
# Add Additional Fees for Specific Category Products in Cart in Woocommerce function wdo_add_additional_cart_fee() { $category_ID = '1025'; // set your Category ID for which you want to applied Additional Charge global $woocommerce; foreach ($woocommerce->cart->cart_contents as $key => $values ) { $terms = get_the_terms( $values['product_id'], 'product_cat' ); foreach ($terms as $term) { if($term->term_id == $category_ID){ $percent = 5; // Additional Charge Amount here in Percent $amount = ($woocommerce->cart->cart_contents_total * $percent ) / 100 ; } } if($amount >0) $woocommerce->cart->add_fee('Additional Charge', $amount, $taxable = false); } } add_action( 'woocommerce_cart_calculate_fees', 'wdo_add_additional_cart_fee' );