How do I use Shipping classes as rules in checkout?
Shipping classes in WooCommerce can be used to group similar types of products. In conjunction with the nShift Checkout extension, these classes can provide different shipping methods or rates based on the product class.
Let's say you have some fragile products in your store, and you want only the carrier PostNord and the shipping method MyPack Home to be available as shipping options when a customer adds one of these fragile products to their cart. Follow the steps below to test.
In WooCommerce:
- Navigate to
WooCommerce -> Settings -> Shipping -> Shipping classes
. Create a new shipping class, for instance, "fragile_product". End the slug "fragile" and add the description "Shipping class for all fragile products". Save your changes. - Go to
WooCommerce -> Products
and select a product that you want to add to the newly created shipping class (use Quick Edit if preferred). - Locate the 'Shipping class' field, select 'fragile_product' from the dropdown menu, and click 'Update'.
In the nShift Portal:
- Log in to the nShift portal and navigate to
Maintenance -> Delivery Checkout
. - Click the 'Search' button, select your checkout.
- Scroll down to 'Parameters'.
- Beneath 'Standard parameters', you have the option to add custom parameters.
- In the 'Name' field, add
shipping_class_fragile
. Note:shipping_class_
must be used as a prefix. - For 'Type', select 'Integer'.
- In the 'Default' field, add "0" and click 'New parameter' to add this parameter.
- Scroll to the bottom of the page and click 'Finish'.
- Click on the checkout again.
- Select the shipping method you want to use for shipping fragile products.
- Below the 'Name' field, you'll find the 'Condition' field.
- Add this condition: shipping_class_fragile = 1. Note: You can combine this condition with standard conditions like
toCountry
,weight
etc. - Click 'OK' and then 'Finish' to save your settings.
Testing the Shipping Class:
Navigate to your WooCommerce store and add a fragile product to your cart, then proceed to checkout. Now, ONLY the Shipping Method you configured for fragile products should appear as an available shipping method in the checkout.
Updated on: 05/08/2023
Thank you!