What can we help you with?
WooCommerce Shipping Plugin – How to Set Maximum Shipping Cost For Domestic and International Services
The shipping cost for a package is calculated based on the weight and dimension of the package and the destination address. But there are few times when the store owner wants to charge a maximum shipping cost to their customers, since high shipping costs scares off most customers from buying their product. This cannot be done with flat rate shipping since some times the shipping cost is lower than the flat rate shipping and the customer have to pay extra for shipping that would not be ideal for business as well. So in this business case, the store owner wants to charge the shipping cost as calculated by the plugin. But when it reaches a certain cost, he wants to charge that constant amount; he doesn’t want the shipping cost to go over certain amount. The customer is currently using the ELEX WooCommerce DHL Express / eCommerce / Paket Shipping Plugin with Print Label. However, this same solution can be used for our other shipping plugins such as:
- 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
In this article we’ll take an example of our plugin ELEX WooCommerce DHL Express / eCommerce / Paket Shipping Plugin with Print Label and put a max shipping cost of $25 for domestic shipping and $50 for international shipment.
Requirements:
Set Up and Configure the ELEX WooCommerce DHL Express / eCommerce / Paket Shipping Plugin with Print Label
You need to purchase the plugin from our site, and set up the plugin to get the shipping rates. To set up the DHL plugin and retrieve the shipping rates, you need to get the API credentials from DHL Express team. You need to open an account and register in https://xmlportal.dhl.com and DHL will provide the Test and Live API credentials. Depending on which set of credentials you received you need to enable/disable the ‘Show DHL Account Rates‘ option under the Rates and services tab in the plugin settings. For Test credentials you need to disable the ‘Show DHL Account Rates‘ option, and for live credentials you need to enable the ‘Show DHL Account Rates’ option.
Make sure all your products (simple and variations) have weight and dimensions in them. You can add weight and dimension while editing the product. Go to shipping tab under the product data and fill up the fields ‘Weight‘,’Length‘,’Width‘ and ‘Height/Thickness‘. The plugin requires these data to calculate shipping and the packing option in the plugin settings. Once done, enable the DHL Express services in the plugin settings under the ‘Rates and Services Tab’ with the product code ‘N’ for Express Domestic, ‘P’ for Express Worldwide, ‘D’ also Express Worldwide (doc type) and U also Express Worldwide (doc type). Different countries require different services, and so depending on the requirement the API will automatically return rates for one of the above services. Now, check if you’re getting the DHL shipping options in the Cart page. If you’re not getting any shipping rates, please make sure you have the address correct or contact our support team.
Now on the cart page, for a domestic shipping when the shipping cost is below $25 it will show the actual shipping cost calculated by the API:
And when you add more items the shipping cost will increase as the package weight increase as well. So in the below image you can see that when I increased the number of items in cart the shipping cost crossed the $25 restriction the shop owner wanted to set.
How Can we Set The Max Shipping cost?
Our developers have come with a solution where you can configure a code snippet and add it using code snippet plugin by Shea Bunge. Its a safe way to add code snippets using the plugin, instead of adding it directly to the functions.php in the theme folder. If you add code snippets in functions.php and there’s some error in the code, your whole site could crash. Hence its wise to use the code snippet plugin which you can download from the WordPress plugin repository – Download Link. You can install the plugin on your WP plugin page and to add the code go to WordPress menu >Snippets>Add New Snippet.
Add the below code and save and activate. I’ve added as comments where you need to do changes according to your requirements, you need to replace the ‘TH’ with your shop’s base country code. It should be a two character code. Enter the max shipping cost you want to set for domestic and international shipping.
add_filter('woocommerce_package_rates', 'wf_modify_rate', 10, 3);
function wf_modify_rate( $available_shipping_methods, $package ){
$origin_country = 'TH'; // Configure the country code of the shop base country.
$max_amount_domestic = 25; // Configure the max shipping cost for domestic shipping.
$max_amount_international = 50; // Configure the max shipping cost for International shipping.
$max_amount = ($package['destination']['country'] == $origin_country) ? $max_amount_domestic : $max_amount_international;
$item_count = 0;
foreach ($package['contents'] as $key => $item) {
$item_count += $item['quantity'];
}
foreach ($available_shipping_methods as $methord_name => $methord) {
if( $max_amount < $available_shipping_methods[$methord_name]->cost ){
$available_shipping_methods[$methord_name]->cost = $max_amount;
}
}
return $available_shipping_methods;
}
With this solution now you’ll have the max shipping cost for domestic and international services restricted to the value you have provided. So when we try with the previous domestic shipping when the shipping cost was over $25 ( 27.54 to be accurate) after the code snippet is added it will be restricted to $25
So now even if we add 100 items to cart it will still show the shipping cost as $25.
Now when we try for International address with the same quantity (100), it will still show the $50 restriction we have provided in the code snippet.
With this solution you can easily charge the actual shipping cost for smaller and lighter items and charge a fixed amount without allowing the shipping cost to be too high scaring most of the customers about the shipping cost. And this would attract more customers to order in bulk as well, since the shipping cost is fixed after certain cost independent of the number of products you order.
Hope this article have helped you with your case. If you need help setting up the plugin and the code snippet you can always contact our team.
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.