Skip to content
Advertisement

Sell some products only on a specific day in WooCommerce

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.

Advertisement

Answer

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.

If the item is in cart but not purchasable anymore, It’s auto removed (on cart or checkout) displaying an error message.

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:

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement