WPSlash

Make Products Available only on specific days of week

Friday October 23, 2020

Here is an example on how to make products unavailable all the days except from some days depending on the product category.

On the following example we are making the products with Category Name “FANCY MENU” to be available only on Tuesday and Wednesday

You can copy the following code under your functions.php and adjust it to your needs

function wpslash_woofood_enable_product_specific_days( $purchasable, $product ){
	
$product_id =$product->get_id();
	if ( $product->is_type('variation') ){
        $product_id = $product->get_parent_id();
    } 

	
        $terms = get_the_terms( $product_id, 'product_cat' );
	$product_categrories = array();
	foreach ($terms as $term) {
    $product_categrories[] = $term->name;
   
}
if(in_array("FANCY MENU", $product_categrories)  )
{
	if(date('l') =="Tuesday" ||date('l') =="Wednesday" )
	{
			return true;
	}
	else
	{
		return false;


	}

}
	  else
	  {
		  	  return true;


	  }
	 
return true;
}
add_filter( 'woocommerce_is_purchasable', 'wpslash_woofood_enable_product_specific_days', 99, 2 );
add_filter( 'woocommerce_variation_is_purchasable', 'wpslash_woofood_enable_product_specific_days', 99, 2 );

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Articles

Tutorials

How to Set Up WooCommerce Payment Gateways for Food Delivery: Stripe, PayPal, Cash on Delivery, and Local Payment Methods (Complete Guide for Restaurant Owners)

Why Choosing the Right Payment Gateway Matters for Your Restaurant Ordering Business Here’s a number that should keep every restaurant owner up at night: nearly 70% of online shopping carts get abandoned before checkout. For food delivery sites, the stakes are even higher because hungry customers won’t wait around. If your payment process feels slow, […]
March 26, 2026
Tutorials

How to Protect Your WordPress Restaurant Ordering Site from Spam Orders, Fake Submissions, and Bot Attacks (Complete Security Guide)

Why Restaurant Websites Are Prime Targets for Spam and Bot Attacks (And What’s at Stake) If you’re running a WordPress restaurant ordering site, you’ve probably already noticed something unsettling: fake orders trickling in, bizarre form submissions, or a sudden spike in account registrations from email addresses that look like keyboard smashes. You’re not imagining things […]
March 26, 2026
Tutorials

How to Optimize Restaurant Food Photography and Image Compression for Faster WooCommerce Menu Pages (Complete Guide)

Why High-Quality Food Images Make or Break Your Restaurant’s Online Orders Here’s a stat that should grab your attention: studies consistently show that menu items with high-quality photos receive up to 30% more orders than those without images. When customers can’t smell or taste your food through a screen, photography becomes your most powerful selling […]
March 25, 2026