mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://stackoverflow.com/questions/77897236/disable-free-shipping-until-a-specific-date-in-woocommerce
13 lines
616 B
Text
13 lines
616 B
Text
add_filter( 'woocommerce_package_rates', 'disable_free_shipping_until_specific_date', 10, 2 );
|
|
function disable_free_shipping_until_specific_date( $rates, $package ) {
|
|
$threshold_date = '2024-02-25'; // Threshold date until free shipping is disabled
|
|
|
|
// Loop through shipping rates for the current shipping package
|
|
foreach ( $rates as $rate_key => $rate ) {
|
|
// Targeting free shipping and specific date
|
|
if ( 'free_shipping' === $rate->method_id && time() <= strtotime($threshold_date) ) {
|
|
unset($rates[$rate_key]); // Remove shipping rate
|
|
}
|
|
}
|
|
return $rates;
|
|
}
|