I need to add a handling fee to products in a Woocommerce store, but I don’t want it to add the fee if the only items in the cart are virtual/downloadable.
This is what I have so far, but it adds the fee to any order.
// Hook to add a handling fee
add_action( 'woocommerce_cart_calculate_fees','wpcover_handling_fee' );
function wpcover_handling_fee() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$subtotal = WC()->cart->get_subtotal();
//set our subtotal amount
if($subtotal > 1) {
//set our fee amount
$fee = 1.50;
//you can change the title of the fee as it appears in the cart
$woocommerce->cart->add_fee( 'Handling', $fee, true, 'standard' );
}
}
New contributor
monkeymays is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.