What can we help you with?
Show Australia Post Satchel Rates or Custom Packing Regular Post based on Order Weight on WooCommerce
This is a business case from a customer using our ELEX WooCommerce Australia Post Shipping Plugin with Print Label & Tracking. He wants to show the satchel rates if the order weight is 5 kg or below, and hide the satchel option and show the custom packing regular parcel post shipping option if order weight is over 5 kg. Prepaid Parcel Post satchels offer you a convenient way to send parcels anywhere within Australia. Their Parcel Post delivery service will ensure your parcels are delivered in 2 or more business days within Australia. Parcel Post 500 g satchels are for items weighing no more than 500 g. And 3 kg satchel is up to weight 3 kg and 5 kg satchel can hold up to 5 kg. But even the dimension of the box or product matters, since Australia Post gives only two dimensional limit for the satchel. You need to make sure the product fit into the satchel provided by Australia Post.
Right now if we enable both the services both options will show up. And if the order weight is over 5 kg, the plugin takes another satchel package and pack the item in a satchel so we have two satchel rates added along with the Regular parcel post option. In our plugin settings we don’t have the option to hide or disable services by weight of the order.
How to achieve this? We’ll discuss in this article along with the requirements to make this work.
ELEX WooCommerce Australia Post Shipping Plugin with Print Label & Tracking
Australia post plugin has three different options for the Rates and services:
- Non-contracted rates: Here you get the satchel rates/letter option as well as the Regular, Express, Courier Post options.
- Contracted: Here you have two options Eparcel or the Startrack account type and you can print labels as well. But you don’t have the option for Satchel rates.
First you need to purchase the Australia Post plugin and set it up. The API key should be provided by Australia Post during registration here. If you’re using non-contract account type you need to disable the contract option and enter only the API key. Please note only the contract account type has the option to print labels and manifests. The non-contract set up will allow you to get the shipping rates in the Cart and Checkout pages, but it will not have the print label and manifest features. Once the account set up is done, go to the ‘Rates and services tab’ in the plugin settings,and enable the domestic services. If you enable the option for Extra cover and signature the plugin adds additional charges so if you don’t want to have the additional charge on shipping you can disable that option.Now once all set up is done, please add a few products to cart and check if you’re getting any Australia Post services in the cart/checkout page. All products need to have weight and dimensions set up in advance. If you’re using ‘pack items individually’ or ‘weight based packing’, you need to add dimension to the products such that at least for 2 dimensions, the value is 5 cm. For example, 5 x 5 x *cm, where * can be any non-zero value. If you’re still not getting any shipping options, do contact our support team here.
Configure the Code Snippet to Hide Shipping Methods by Order Weight
To hide the satchel rates when order weight is over 5 kg you can use the following code snippet. It’s best to install the code snippet plugin and add the code there. Download the code snippet plugin from WordPress by Shea Bunge, Download link: https://wordpress.org/plugins/code-snippets/.
Install the plugin on your site, and click on Add new snippet and copy the below code and add as a new code and save changes and activate the code snippet. This method of adding the code is safe and does not break the site even if there was any syntax error or fatal errors with the code.
add_filter( 'woocommerce_package_rates', 'show_shipping_method_on_order_weight', 10, 2 );
function show_shipping_method_on_order_weight( $available_shipping_methods, $package ) {
$order_weight = 0;
foreach( WC()->cart->cart_contents as $key => $values ) {
$product_weight = woocommerce_get_weight($values[ 'data' ]->get_weight(),'lbs');
$quantity = $values['quantity'];
if($product_weight && $quantity){
$order_weight = $order_weight + $product_weight*$quantity;
}
}
$weight_oz = $order_weight*16;
if($weight_oz >= 176.37){
$shipping_services_to_hide = array(
"wf_australia_post:REGULAR_SATCHEL",
"wf_australia_post:EXPRESS_SATCHEL"
);
}else{
$shipping_services_to_hide = array('wf_australia_post:AUS_PARCEL_REGULAR','wf_australia_post:AUS_PARCEL_EXPRESS');
}
foreach ( $shipping_services_to_hide as $key => $value ) {
unset( $available_shipping_methods[$value] );
}
return $available_shipping_methods;
}
This code snippet will hide the Satchel rates if the order weight is over 5 kg. If the order weight is below 5 kg, it will hide the Regular Parcel Post and Express Post.
Now when you add a product that weighs 0.5 kg about 9 items, only the Satchel rates show up. See below image.
And when you add about 12 items of the same and weight is over 5kg, then the satchel rates are hidden and the Regular and Express post options are the only ones available in cart page.
This way when the satchel option shows the Regular and Express custom package rates gets hidden automatically and when the weight is over 5kg satchel options get hidden automatically. If you have any other requirement to hide shipping methods or show the shipping methods by order weight you can simply configure the code snippet. If you want to change the weight limit to hide shipping right now I’ve given 176.37 ounces, since the code snippet is written to take weight in ounces.
You can change that value in the snippet according to the limit you want to set. And for the shipping options to hide I’ve given the values “wf_australia_post:REGULAR_SATCHEL”,”wf_australia_post:EXPRESS_SATCHEL” You can right click on the shipping option in cart and click on Inspect to get the Shipping ID you want to hide. And when weight is over 5kg (limit) you can define which shipping option to show.
In the current code I’ve added ‘wf_australia_post:AUS_PARCEL_REGULAR’,’wf_australia_post:AUS_PARCEL_EXPRESS’.
Hope this article have helped with your business requirement. Do let us know if you have any requirements. Our team is here to help!
To explore more details about the shipping plugins, please check out the product pages.
- ELEX WooCommerce DHL Express / eCommerce / Paket Shipping Plugin with Print Label,
- ELEX WooCommerce Australia Post Shipping Plugin with Print Label & Tracking,
- ELEX WooCommerce USPS Shipping Plugin with Print Label,
- ELEX Stamps.com Shipping Plugin with USPS Postage for WooCommerce,
- ELEX EasyPost (FedEx, UPS & USPS) Shipping & Label Printing Plugin for WooCommerce
You can also check out other WooCommerce and WordPress plugins in ELEX.