With Woocommerce I would like to sell certain defined items on Sunday only. If anyone tries to purchase outside of Sunday, it should give an error. The remaining items in the shop can be purchase anytime.
Is this possible? Any track is really appreciated.
Example - I have a product called “Sunday Tapas” which is product code “2795”. I want this product available on Sunday’s only. Everything else in the store should be available everyday as normal.
This code snippet will prevent the Sunday product from adding into cart.
As your requirement is that you want proceeding from checkout, You can use the below code snippet. It will show some message in checkout, if the cart items contains invalid product.
Based on "Enable Woocommerce shop purchases only during a daily time range" answer code, changed to handle "days of the week" (So "Sunday" for you).
The following will enable purchases for a specific item (the product Id
2795
) on sundays only.Outside sundays, an error message is displayed on the product page, indicating that the product is only purchasable on sundays.
You will have to set your time zone in the first function and your specific products in the second function.
The code:
Code goes in function.php file of your active child theme (or active theme). Tested and works.