WooCommerce – Hide Shipping Methods if items of a specific Shipping Class is NOT in Cart

This article will help you hide shipping methods based on the type of products present in the cart. If you are using the following shipping plugins on your WooCommerce store and want to display shipping methods based on the shipping classes, this article will surely help you.

Below snippet will hide shipping methods if none of the items in the cart belongs to the specific Shipping Class.

Use the array variable $shipping_classes to define the shipping classes.
Define the services to hide using the array variable $shipping_services_to_hide.

If you want to hide all the shipping methods, you can refer to this snippet article for reference code.

 

.button {
border-radius: 5px;
background-color: #5472D2;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 35px;
padding: 20px;
width: 200px;
transition: all 0.3s;
cursor: pointer;
margin: 5px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.3s;
}
.button span:after {
content: ‘\00bb’;
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.3s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}

 

2 thoughts on “WooCommerce – Hide Shipping Methods if items of a specific Shipping Class is NOT in Cart

  1. harish says:

    how to add or remove shipping class based on the quantity of product added to cart. like if 3 or > 3 of a product added, then apply a shipping class “free” otherwise apply normal shipping.

Leave a Reply