Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Add a Handling Fee for Specific Product Categories in WooCommerce?

Do you want to add the extra delivery fees for certain product categories in addition to the available shipping options. This code adds a handling fee to the cart total if any product in the specified category (with the ID ’50’) is present.

add_action( 'woocommerce_cart_calculate_fees','ts_custom_category_fee', 20, 1 );
function ts_custom_category_fee( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    // Set HERE your categories (can be term IDs, slugs or names) in a coma separated array
    $categories = array('50');
    $fee_amount = 0;

    // Loop through cart items
    foreach( $cart->get_cart() as $cart_item ){
        if( has_term( $categories, 'product_cat', $cart_item['product_id']) )
            $fee_amount = 60;
    }

    // Adding the fee
    if ( $fee_amount > 0 ){
        // Last argument is related to enable tax (true or false)
        WC()->cart->add_fee( __( "Handling Fees", "woocommerce" ), $fee_amount, false );
    }
}

Output

When customer chooses any product from the category ‘Electronic’ will be shown an extra delivery or Handling fees as shown below.

How to Add a Handling Fee for Specific Product Categories in WooCommerce? - Tyche Softwares

Same as the above, you can also charge additional fees based on shipping classes. You can add a WooCommerce fees based on shipping class and item quantity that will dynamically increase the additional costs as the quantity increases.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x