-
AuthorPosts
-
June 2, 2022 at 11:41 am #1353900
Hello,
I have configured the shipping zones so that delivery is free from a certain amount (69€ for France). It works but flat rate shipping is still offered to the customer. The customer therefore has the choice between free delivery and paid delivery, which is irrelevant. I wish that when free shipping is available, flat rate shipping is not offered. But I would like to leave the possibility for the customer to choose free delivery in store or delivery by Mondial Relay.
To summarize, I would like to offer all shipping methods except flat rate shipping when the amount to have free shipping is reached.
How can I do this?Thank you very much,
Best regardsJune 4, 2022 at 5:27 pm #1354154Hey laboiteapixels12,
Thank you for your patience, try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:function check_for_free_shipping() { ?> <script> (function($){ function check_shipping() { setTimeout(function () { $('#shipping_method').each(function() { $(this).find('li input.shipping_method').each(function(){ var shipping = $(this).attr('id'); $(this).closest('li').addClass(shipping); }); }); $('#shipping_method .shipping_method_0_free_shipping1 + .shipping_method_0_flat_rate2').css({ 'display': 'none'}); }, 1000); } check_shipping(); $('#top.woocommerce-cart button[name="update_cart"]').click(function(){ setTimeout(function () { location.reload(true); }, 1000); }); })(jQuery); </script> <?php } add_action('wp_footer', 'check_for_free_shipping');
This gets each input ID and adds it as parent class (li) and hides the sibling li with css if the free shipping option is available and checks for update cart button click should user change quantity.
Please note that I had to add a 1s delay because woocommerce is slow to add the free shipping element, there is nothing I can do about that.Best regards,
MikeJune 4, 2022 at 5:59 pm #1354159Hi Mike,
I tried adding the code in child theme functions.php file (with Filezilla by FTP), but it doesn’t change anything at all. The flat rate shipping is still offered when the free shipping option is available :(
Could you check why the code doesn’t work ?
Thank you very much,
Best regards,Audrey
June 4, 2022 at 6:21 pm #1354162June 4, 2022 at 6:30 pm #1354163Hi,
Indeed, it works fine on the checkout page. But on the cart page, when I enter my address to calculate the shipping costs, there is still the flat rate shipping that appears. It’s only if I refresh the page that it disappears. Could you verify in private browsing (so that your address is not already indicated in the calculator of the delivery costs) ?
Thank you !
Best regards,
AudreyJune 4, 2022 at 6:43 pm #1354164Hi,
I just found a solution ! I added this code :
add_filter( ‘woocommerce_package_rates’, ‘bbloomer_unset_shipping_when_free_is_available_in_zone’, 9999, 2 );
function bbloomer_unset_shipping_when_free_is_available_in_zone( $rates, $package ) {
// Only unset rates if free_shipping is available
if ( isset( $rates[‘free_shipping:1’] ) ) {
unset( $rates[‘flat_rate:2’] );
}
return $rates;
}And now it seems it works fine !! :)
Thank you Mike for your help,
Have a good day,Best regards,
AudreyJune 4, 2022 at 8:10 pm #1354170Hi,
Glad to hear that you have this sorted out, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Hide flat rate shipping when the amount to have free shipping is reached.’ is closed to new replies.