Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Woocommerce Hide Shipping Address and Shipping Method by Product Category WordPress


I have been searching everywhere for some php code or plugin that would allow me to hide all shipping information by product category. I have a situation where I don't require any shipping information or shipping charges for a particular category.

The item is not a virtual or a downloadable product and by selecting virtual it does other things that I do require.

Answers (4)


Reigel Gallarde answers:

this can be critical...
what if you have multiple categories involved in the cart?

have you found a solution yet?

Steven Sinfield comments:

No solution as yet. :(

Reigel Gallarde comments:

The only thing I can think of that can make a product to have no shipping is to make it virtual...
In your case you can make a filter for the is_virtual function and it should work without hurting other products...

so this should do it, I put it on pastebin because of formatting problem on this site.

Let me know if this is what you need.


Reigel Gallarde comments:

in the code, replace 'uncategorized' with your category..

Reigel Gallarde comments:

please replace the if with this, I have done it the opposite on that one..
also added is_checkout(), so it will work only on checkout page...

if( is_checkout() && has_term( 'uncategorized', 'product_cat', get_post($product->get_id())) )

Steven Sinfield comments:

In uncatergorized do I put the category description, slug or id?

Reigel Gallarde comments:

as per
it can be the term name/term_id/slug or array of them to check for.

also, if this is a variation, you need to change get_id to get_parent_id


Farid answers:

Can you share any related screenshots or your site URL for reference?


Steven Sinfield comments:

Here is one of the screenshots of the information I want not to display for a particular product category.

Steven Sinfield comments:

And the zero dollar shipping field here because everything in this particular category has free shipping.

Farid comments:

If you are searching for plugin solution, try By using this plugin, you could add restrictions on the certain product or product categories.

Steven Sinfield comments:

That is a paid plugin I just want some PHP code that I can put into the functions.php of my theme to do exactly what I need.

Farid comments:

Then you've might want to look into the woocommerce_package_rates filter, which allows you to filter the set of shipping options that are available to the customer.

For the different conditions code examples based on different WC plugin versions you can consult

If you have the basic coding knowledge and can get the product IDs then an example would be something like this:

// add this snippet to functions.php:
add_filter( 'woocommerce_package_rates', function ( $rates, $package ) {
// examine $package for products. this could be a whitelist of specific
// products that you wish to be treated in a special manner...
$special_ids = array( 1, 2, 3, 4, 5 );
$special_product_present = false;
foreach ( $package['contents'] as $line_item ) {
if ( in_array( $line_item['product_id'], $special_ids ) ) {
$special_product_present = true;

$rates = array_filter( $rates, function ( $r ) use ( $special_product_present ) {
// do some logic here to return true (for rates that you wish to be displayed), or false.
// example: only allow shipping methods that start with "local"
if ( $special_product_present ) {
return preg_match( '/^local/', strtolower( $r->label ) );
} else {
return true;
} );

return $rates;
}, 10, 2 );

You can set your own condition where only allow shipping methods that start with "local" in the code.



Arnav Joy answers:

can you please check this link

or this

Steven Sinfield comments:

Hi Arnav,

As I am not a programmer and I know what I want I have been to both of those sites and was a little overwhelmed by the tech talk.


Mohamed Ahmed answers:

Could you send me your site url to my email.
It's easy case and I will fix it.
my email: [email protected]