Adding free shipping above fixed amount in WooCommerce order is really cool. Customer get free shipping on particular orders, also its boost chances of more selling of products. In WooCommerce plugin, we can add free shipping above fixed amount orders in cart amount via plugin or code. We have an option to add free shipping or flat charges above fixed amount of orders in woo commerce.
Table of Contents
A condition
Consider a situation where you have to provide free shipping to customer on order above 100$ or 100₹ and below that you charge 5$ or 50₹ as flat shipping charge. To complete this scenario you have to add free shipping and flat rate attribute from shipping option in WooCommerce. Customer whose order above
100$ or 100₹ will get two option on checkout page to select :
- Free shipping
- Flat rate cart
This two option may create confusion for customer and may leave bad impression because both option can be checked (well nobody will select paid shipping if free shipping is there).
Solutions for adding Free shipping above fixed amount
In order to fix this we have two options :
- Install third party plugin
- Add a simple code in functions.php file
You can choose to install plugin but if plugin is poorly coded then it may slow down your checkout page which is not recommended (specially when you taking payment from customer). Also plugins make websites slow.
In second option, all you have to do it add a simple code in your functions.php file (In your child theme). If you add code in main theme functions.php file then you may loose code when theme will update.
To add code follow these simple steps to :
- Login into your WordPress dashboard.
- Go to appearance – select theme editor – click on ‘I understand’ option in popup.
- on left hand side and select your child theme and click on select (where it says select theme to edit).
- On same right side bar, click on functions.php file.
- In text editor, add below code just above the end of php tage (?>).
- After adding the code, click on save and go back to dashboard option.
/**
* Hide shipping rates when free shipping is available.
* work on WooCommerce above 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
Now you can check your cart by adding products above your specified amount, free shipping will be automatically updated in cart. Try the code and let us know how it goes. Any questions or queries ? Comment below or contact us for support
[caldera_form id=”CF60ca2e3ccf64f”]