Select a particular package type for a shipping method based on order total weight

This code snippet will help you to select a particular package type for a shipping method based on order total weight.
The above is a ready to use snippet which only requires changes in these three lines:
1. $weight_less_than[] = array(‘weight’=>1, ‘service_code’=>’US-XM‘, ‘package_type’=>’USPS Legal Flat Rate Envelope‘); //Enter proper values or remove this line
2. $weight_greater_than[] = array(‘weight’=>1, ‘service_code’=>’US-XM‘, ‘package_type’=>’Package‘); //Enter proper values or remove this line
3. $weight_equal_to[] = array(‘weight’=>1, ‘service_code’=>’US-XM‘, ‘package_type’=>’USPS Legal Flat Rate Envelope‘); //Enter proper values or remove this line
the 1st line states that for order total weight less than 1, if a customer selects “USPS Priority Express service“, then the rate for the corresponding package type “USPS Legal Flat Rate Envelope” should be picked up.
Similarly, the other lines represent the case when total order weight is greater than and equal to 1.
How to understand services codes?
No Problem. You can easily find the service code by the following method :
– Go to the cart page and fetch the rates for an order as shown below :
In the screenshot below, you can see “Priority Mail”. Take the mouse pointer just above the service name, do a right click and then click on inspect.

A small window called developers tools will open at the bottom of the page. You can find the service code from here.

Element

Element

Leave a Reply