Limit Which Products Can Use the WooCommerce USPS Shipping Gateway

Recently a member of the Advanced WooCommerce Facebook Group asked:

“I wanted to see if it were possible to limit which products can use the Woo USPS plugin shipping…”

There is almost always an option to purchase an extension from WooThemes.com that offers the needed functionality. In this case that extension would be WooCommerce Conditional Shipping and Payments. The benefit of using an extension like this is, it will be maintained for you by the author of the plugin.

In some cases a premium plugin offers way more code than needed and it may be worth a custom solution. I have written a quick set of functions that achieve the OP’s request:

 

Add this code snippets can be added to your theme / child-theme’s functions.php file.

Before adding the snippets, make sure you clear your WooCommerce cache ( WooCommerce → System Status → Tools → WC Transients → Clear transients ), as shipping methods are cached.