I just require a small help on displaying the correct shipping fees in my WordPress and woocommerce site.
I have set my shipping fees as the following:
- Flat rate (Delivery): $10
- Free Shipping (Free Delivery)
- Local Pickup (Pickup): $0
When I make an order and go onto the checkout page, it gives me the options to select from for shipping underneath the order total. I don’t want the user to be able to choose out of the options.
Basically what I require is the following:
- If the service type is Pickup, hide delivery options and only show the local pickup option
- If the service type is delivery and the order total is $60 or below, then only show the flat rate option.
- If the service type is delivery and the order total is above $60, then only
show the free shipping option.
Does anybody know how to set this? Also, one thing to note, on the menu page when you add to the cart, it adds a delivery fee automatically when you open the order review container at the bottom, would be good to not set this charge until checkout if possible?
Here is the website containing the food items: https://puffpastrydelights.com/order-online/
I’ve tried this so far but it doesn’t work:
add_filter( 'woocommerce_package_rates', 'bbloomer_unset_shipping_when_free_is_available_in_zone');
function bbloomer_unset_shipping_when_free_is_available_in_zone( $rates ) {
$service = $_POST['wfs_service_type'];
if ($service == 'pickup') {
unset( $rates['flat_rate:1'] );
unset( $rates['free_shipping:3'] );
}else if ($service == 'delivery'){
unset( $rates['local_pickup:2'] );
if ( isset( $rates['free_shipping:3'] )) {
unset( $rates['flat_rate:1'] );
}
}
return $rates;
}
2
Answers
Your
service_type
is saved in a cookie. you can retrieve by$_COOKIE
. Try the below code.Updated
You need first to set the posted delivery type in a WC Session variable. Then some changes in your code will be needed as follows:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Don’t forget to empty your cart to refresh shipping cached data.