0

To open, I do not know PHP. I have cobbled this snippet together from the information in these two links -> Show and Hide div based on day and time and -> https://avada.io/woocommerce/docs/disable-shipping-methods-certain-products.html

My desired outcome is to remove the delivery options from checkout while leaving the two pickup options.

Currently the snippet is running, but doesn't do anything, however if I do not return the $rates properly, all of shipping options including pickup get nerfed, so I know I'm in the ballpark.

Here is the snippet I'm running

function lf_hide_shipping_for_closed_hours( $rates ) {

    date_default_timezone_set('America/Vancouver');
    $currentTime = date("Gi");

    $deliveryStart = 1200;
    $deliveryEnd = 1945;

    // Check if we are open
    if ($currentTime <= $deliveryStart && $currentTime > $deliveryEnd){
        foreach ( $rates as $rate_id => $rate ) {
            if ( 'szbd-shipping-method:5' === $rate->get_method_id() ) {
            unset( $rates[ $rate_id ] );
            }
        }
    }
    return $rates;
}

add_filter( 'woocommerce_package_rates', 'lf_hide_shipping_for_closed_hours', 100 );

How can I modify my snippet to achieve this?

Edit, here is the site url in question.

https://dev-site.potorium.ca/

lforsey
  • 17
  • 4

0 Answers0