Prevent Checkout Based on Shipping Method & Class in WooCommerce

The code in this download folder enables you to prevent checkout for specific products in WooCommerce. The code works based on :

  1. The shipping class assigned to the product. ( in this example we use a shipping class slug of dangerous-goods.
  2. The shipping method chosen on the cart and checkout pages. ( in this case we use the Express shipping method which uses the ID flat_rate:10 ).

The warning notice displays on the cart and checkout page based on the above conditions.

You can use the code with any shipping class and any shipping method.

Demo Video

Shows the product with the dangerous-goods shipping class slug prevented from checkout when the Express shipping method is selected and a notice displayed in the cart and checkout pages.

Installation

Add the code to the end of your child themes functions file.

Code Settings

  • Swap out the shipping method ID on line 16 from flat_rate:10 to match the shipping method ID you don’t allow for your product.
  • Swap out the shipping class slug dangerous-goods to match the slug of your shipping class.

Download Folder

Related Code

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.