function my_custom_add_cart_fee() {
global $woocommerce;
$productID = 21; // Sample product ID that needs to add additional FEE # Album
$addtionalFEE = 10; // Additional Fee cost per product @ this example product id "21"
$addtionalCost = 0;
$productFound = false;
// Get the all cart items
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
// Check if the product ID that needs to add Addtional Fee Exist
// Get the product quantity and multiply with the additional FEE
if( $values['product_id'] == $productID ){
$addtionalCost = $values['quantity'] * $addtionalFEE;
$productFound = true;
break;
}
}
// If product found on cart add this Additional FEE
if( $productFound ){
$woocommerce->cart->add_fee( __( get_the_title($productID).' Additional FEE', 'woocommerce'), $addtionalCost );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'my_custom_add_cart_fee' );
How to add additional FEE in Woocommerce Cart
Adding additional FEE on woocommerce cart is very simple by simply using woocommerce hook “woocommerce_cart_calculate_fees“, but sometimes we just don’t addtional FEE in every product purchase or checkout.This simple snippet will give you an idea how to add a logical condition on how to add Additional FEE based on product ID purchased.Copy and paste this code to your functions.php file.



















