I’ve written in a previous article about how you can implement a 3-day shipping notice on the WooCommerce Checkout Page. Suppose for example, the online store is a Monday through Friday operation, and should a customer place an order on either Friday, Saturday, or Sunday, then display a shipping date for Monday. However, any order placed on the weekdays Monday through Thursday would display a message for shipping the next day.
The Newsletter for PHP and MySQL Developers
Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.
π° Get your brand, product, or service the attention it deserves with affordable classified ad placement in the OpenLampTech newsletter. I appreciate your support!
Note: All of the examples in this post are part of a development/learning WooCommerce install using the default Storefront theme. PHP code is placed in the child themeβs function.php file.
The below code placed in the child theme functions.php file will accomplish this:
add_action( 'woocommerce_review_order_after_submit', 'custom_woo_checkout_shipping_dynamic_date_notice' , 9999, 3 ); function custom_woo_checkout_shipping_dynamic_date_notice() { date_default_timezone_set( 'America/Chicago' ); $is_virtual_product = false; //get all the items in the cart so we can see if there are any virtual items foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item_value ) { if ( $cart_item_value['data']->is_virtual() ) $is_virtual_product = true; //there is a virtual product in the cart } if ( $is_virtual_product ) { return; } elseif ( date('N') >= 5 ) { // the day is Friday, Saturday, or Sunday _e('We are closed on weekends. Your order should be shipped on '.'<b>'.date( 'l, F jS, Y', strtotime( 'next monday' ) ).'</b>'. '. Thank you for your understanding.', 'woocommerce'); } else { _e('Your order should ship on, '.'<b>'.date( 'l, F jS, Y', strtotime( ' + 1 days' ) ).'</b>'. ' . Thank you for your business.', 'woocommerce'); } }
Looking at the code, we can see the following taking place:
- Getting all the items in the current cart and if any of them is a virtual product, then returning from the function, essentially doing nothing. (It doesn’t make sense to have a shipping notice for virtual products)
- Using the date() function with the ‘N’ format specifier to get the day number of the week (1 representing Monday, through 7 for Sunday).
- If the day number is not greater than or equal to 5, (>= 5) then it is a Monday through Thursday weekday.
- If the day number is greater than or equal to 5, this day falls on either Friday, Saturday, or Sunday and will display a shipping notice for the following Monday.
Should I try to place an order on a Saturday (the date of this article’s section is on Saturday, March 18th, 2023), then I get this shipping notice:
However, visiting the Checkout page on Monday, March 20th, 2023 displays a shipping notice for the next day which is Tuesday:
While I am no expert in WooCommerce, I enjoy learning to use my existing PHP skills in this environment. Feel free to share any suggestions for content you would like for me to research and write about. Thank you.
Credit Resources
Once again, fantastic resources online like this one helped me understand the concepts in order to implement a working code solution: https://www.businessbloomer.com/woocommerce-show-dispatch-est-shipping-date-single-product/.
If you see any mistake(s) in the code or know of a better working solution, please share freely in the comments section.
Thank you for reading this post. Please share it with someone else who would enjoy it as well.
Josh Otwell has a passion to grow as a PHP Developer, SQL expert, and technical blogger/writer.
Disclaimer: The majority of examples in this post, are performed in a personal development/learning workstation environment and should not be considered production quality or ready. Your particular goals and needs may vary. Like always, just because you can do something doesn’t mean you should. My opinions are my own.
More ways I can help
- Any of the Web Squadron Mastery Modules can help you with your online web entrepreneurial endeavor(s).
- Get a handle on Google Analytics with this course by the folks over at The Content Technologist.
- Need hosting for your next web application or WordPress site? I highly recommend Hostinger and use them to host my niche bass fishing site. The service is second to none.
- π5 Truths I’ve Come To Realize As a Self-taught Developer
- Mobile wallpapers, digital downloads, photos, development services, and content – all on one Kofi Shop Page. Find your next digital purchase today!
Disclosure: Some of this blog post’s services and product links are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.
The Newsletter for PHP and MySQL Developers
Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.
π° Get your brand, product, or service the attention it deserves with affordable classified ad placement in the OpenLampTech newsletter. I appreciate your support!