skip to Main Content
IMPORTANT
There is currently an unexpected delay in support response time due to a personal emergency.
I greatly apologize for the inconvenience and will respond to each ticket as soon as possible.

Limit Options Based On Date

There are some scenarios where a shipping option is only available on certain days of the week. Let’s say you offer ‘Saturday Delivery’, but this option is only available to customers who purchase their items on a Wednesday or Thursday. To make this happen, you will need to first setup a row in your table of rates for this option. Then with the help of an external code snippet, you can show or hide this option depending on what day of the week today is. The screenshot below illustrates the two options available to a customer: Standard Delivery and Saturday Delivery. The code snippet that follows shows how to modify the output so that Saturday Delivery only shows up on the cart page on Wednesdays and Thursdays.

example-delivery-date

function modify_saturday_delivery( $packages ) {
    global $woocommerce;

    foreach( $packages as $key => $pkg ) {
        if( isset( $pkg['rates']['table_rate_shipping_saturday-delivery'] ) &&
            (date('l') != 'Wednesday' && date('l') != 'Thursday') )
                unset( $packages[ $key ]['rates']['table_rate_shipping_saturday-delivery'] );
    }

    return $packages;

}
add_action('woocommerce_shipping_packages', 'modify_saturday_delivery');
  • Was this article helpful ?
  • yesno
0 out of 0 visitors found this article helpful
Views: 19
Back To Top