Hi folks. I’ve cobbled together a php snippet with the goal of removing all delivery options from the checkout form unless the time is between 1200 and 1945.
Here are the resources I’ve used to put my snippet together
→ How To Disable WooCommerce Shipping Methods for Certain Products – AVADA Commerce
→ php - Show and Hide div based on day and time - Stack Overflow
Here is my snippet
function lf_hide_shipping_for_closed_hours( $rates ) {
date_default_timezone_set('America/Vancouver');
$currentTime = date("Gi");
$deliveryStart = 1200;
$deliveryEnd = 1945;
$condition = $currentTime >= $deliveryStart && $currentTime < $deliveryEnd;
// Check if we are open
foreach ( $rates as $rate_id => $rate_val ) {
if ( $condition ){
if ( 'local_pickup:2' === $rate_val->get_method_id() ) {
unset($rates[$rate_id]);
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'lf_hide_shipping_for_closed_hours', 100, 2 );
It doesn’t work, but if I remove the “return $rates;” line it nerfs all my ordering options.
I’ve played with it quite a bit, some insight would be appreciated.
This is a for a wordpress woocommerce website.
I think my issue might have something to do with a plugin I’m using called shipping zones by drawing. The $rate_val ids I would like restricted are “szbd-shipping-method:5”, “szbd-shipping-method:6”, “szbd-shipping-method:7”, and “szbd-shipping-method:8” which amount to our local delivery zones.
Any input or resources appreciated. Would like to avoid paying ~$100 a year for a plugin for this functionality.