I’m looking for a way to give free shipping on all orders based on weekday of the order. So if someone places an order (let’s say on Monday) it will give him free shipping no matter what type of order quantity/amount/etc.
I’ve tried to hook up something from different other tutorials but I can’t seem to get the part where I change the free_shipping limit + not sure it works since it’s incomplete.
function free_shipping_day( $rates, $package ) {
// valid days
$valid_days = array('Mon');
// current day
$today = date ( 'D' );
// check if it's valid day
if( in_array($today, $valid_day) ){
// clear other shipping methods allow only free
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
}
}
// set free_shipping limit to 0
// show notice
wc_add_notice( __( "Shipping is free today!" ), 'notice');
}
}
add_action('woocommerce_package_rates', 'free_shipping_day');
Any help is very appreciated since I’m kind of stuck with this.
2
Answers
Add the follows code snippet in your active theme’s functions.php –
To make free shipping available on specific days of the week, it requires a different hook to bypass the free shipping limitations (if they exist).
We use
date()
function with “w” parameter that gives an integer from0
(Sunday) to6
(Saturday):To hide other shipping methods when free shipping is available, you can use additionally the following:
Code goes in function.php file of your active child theme (or active theme). Tested and works.