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

How to Hide Specific Shipping Methods For Specific Products in WooCommerce?

Looking to hide a specific shipping method on the WooCommerce cart page based on selected Product IDs? This snippet provides a solution.

add_filter( 'woocommerce_package_rates', 'ts_specific_products_shipping_methods', 10, 2 );
function ts_specific_products_shipping_methods( $rates, $package ) {

    $product_ids = array( 35 ); // HERE set the product IDs in the array
    $method_id = 'flat_rate:2'; // HERE set the shipping method ID
    $found = false;

    // Loop through cart items Checking for defined product IDs
    foreach( $package['contents'] as $cart_item ) {
        if ( in_array( $cart_item['product_id'], $product_ids ) ){
            $found = true;
            break;
        }
    }
    if ( $found )
        unset( $rates[$method_id] );

    return $rates;
}

Output

The below output shows that the “flat rate” Shipping options are hidden based on the specific product IDs on the WooCommerce cart page.

How to Hide Specific Shipping Methods For Specific Products in WooCommerce? - Tyche Softwares

Similarly, you can also hide the specific shipping methods based on product categories in WooCommerce cart page.

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
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.