Drupal Commerce 2.x and shipping conditions

Submitted by gnikolovski on Sat, 01/27/2018 - 11:05

Drupal Commerce 2.x and shipping conditions

Drupal Commerce 2.x and shipping conditions

This blog post has been re-posted with permission from Studio Present Dev blog.

By default Drupal Commerce 2.x and Commerce Shipping modules come with two nice conditions Limit by total price and Limit by shipment weight. But in some cases these conditions are not good enough for restricting shipping methods.

Let's say that you have different shipping prices for different product weights. Defining these shipping methods with Limit by shipment weight condition cannot be done, because it does not allow defining weight ranges.

To fix this problem I created Limit by shipment weight range condition. You can use it to define shipping methods for a specific weight range. For example if total weight of all products in the cart is between 1 and 10kg you can set one shipping price. For weight range between 10 and 20 kilograms you can define another shipping price and so on.

Limit by shipment weight range - Shipping 1-10kg
Shipping 1-10kg

 

Limit by shipment weight range - Shipping 10-20kg
Shipping 10-20kg

 And this is how the Shipping information checkout pane will look like if total weight sum of all products in the cart is between 1 and 10 kilograms.

Limit by shipment weight range
Shipping information pane


The same thing is with Limit by total condition. You cannot use it to define shipping costs based on the total amount of products in the cart for ranges. So, I created another condition called Limit by order price range. You can use it to define shipping prices based on subtotal order price (that is price without any order adjustments) or total order price.

Shipping 10-100EUR
Shipping 10-100EUR

 

You can download or clone sample module from here: https://github.com/gnikolovski/commerce_gnikolovski