Adding a handling fee to your Woocommerce store products without a plugin.

Want to add a handling fee to your Woocommerce store products, but don’t want to buy an expensive plugin? There is an easy way to accomplish this with a snippet.

In the store I am working on, the client wants a handling fee, but only if the product is a physical item that is being shipped. Since they also sell PDF’s that don’t require shipping, we don’t want the handling fee to be added to those. But we do want the handling fee if the order contains both PDF and a physical item.

So here you go – just add the following to your functionality plugin. It is tested and works as of Woocommerce v8+. This code snippet adds a $3 handling fee, but you can change it to whatever price you would like.

/* Add handling fee of $3 to cart at checkout */
add_action( 'woocommerce_cart_calculate_fees','handling_fee' );
function handling_fee() {
    global $woocommerce; 

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    // First test if all products are virtual. Only add fee if at least one product is physical.
    $allproductsvirtual = true; 
    $fee = 0;
    foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {

        $product = $values['data'];

        if( !$product->is_virtual() ){
            $allproductsvirtual = false;
        }
    }
    if ( !$allproductsvirtual ) {
        $fee = 3.00;
    }
    $woocommerce->cart->add_fee( 'Handling', $fee, false, 'standard' );
}

Leave a Reply

Your email address will not be published. Required fields are marked *