My Blog
Adding volumetric weight to woocommerce with a simple function.
- March 16, 2021
- -
- Websites & Hosting Woocommerce Wordpress
- -
- nicolas
Here you have finally created your own eshop and everything is working correctly (payments, shipping, weight calculation, order processing, etc.) and where you are preparing the next steps in the development of your business, an order with the wrong shipping appears (at least that's what you think in principle).
You check the order and realize that the shipping was finally charged correctly, but your courier overcharged you.
So you look for the price list that was delivered to you during your agreement with the courier only to be confronted with the cold truth:
VOLUMETRIC WEIGHT WAS CHARGED.
That damn volumetric weight of it -> (length * height * width) / 5000
And you say now, how will I solve the problem??????
And you start looking for a bunch of plugins in wordpress and woocommerce which, all they do is make your life even more difficult.
Η ΛΥΣΗ ?????
A simple function, so easy and so very useful.
In case you have never passed a function in wordpress before, install the following plugin: https://el.wordpress.org/plugins/my-custom-functions/
Immediately after, go here: (your site address)/wp-admin/options-general.php?page=my-custom-functions
Paste the following code into the window 😉
//dimensional weight function by NicolasLagios.com add_filter( 'woocommerce_product_get_weight', 'custom_get_weight_from_dimensions', 10, 2 ); function custom_get_weight_from_dimensions( $weight, $product ) { $dim_weight = $product->get_length() * $product->get_width() * $product->get_height() / 5000; return $dim_weight > $weight ? $dim_weight : $weight; }
Click where it says Save Changes
Immediately after the page reloads, press where it says OFF (in red) and turn it ON (in green) and press Save Changes for better or for worse.
Finally, because we need to empty the Woocommerce cache, go here: (your site address)/wp-admin/admin.php?page=wc-status&tab=tools
And click clear transients (woocommerce transients)
Now you will see that when the volumetric weight exceeds the normal weight, then the volumetric weight is selected instead of the normal one and end of the wrong charges.
Good luck and please if you want to republish my article, I'm happy to, but also leave a reference to me.
Thanks, Nikos 😉
This post is also available in: Ελληνικά