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 WooCommerce

How to Choose the Best Food Ordering System for Your Restaurant (And Why WooFood is the Ultimate Solution)

If you’re running a restaurant, café, or fast-food business in today’s digital age, offering online food ordering is no longer optional — it’s essential. Customers expect the convenience of browsing your menu, customizing their orders, and checking out seamlessly from their phone or computer. But with so many plugins and systems available, how do you choose the right […]
April 21, 2025
WooFood

How to Disable Coupons for Delivery Orders in WooCommerce

If you’re running a WooCommerce-powered restaurant or food delivery service, you might want to restrict certain coupon codes for delivery orders while keeping them valid for pickup orders. This ensures better control over discounts, prevents misuse, and improves your store’s pricing strategy. Why Restrict Coupons for Delivery Orders? Offering coupons is a great way to attract customers, but in food […]
June 20, 2023
WooFood

How to Automatically Re-Enable Disabled Products in WooFood Once a Day

If you’re running a WooCommerce-powered restaurant ordering system using WooFood, you might have products that automatically get disabled due to stock limits or availability settings. To ensure a smooth customer experience, you can automate the re-enabling process using a scheduled WordPress cron job. This method allows you to reset all product availability once a day, ensuring your menu stays active without manual intervention. Why […]
March 8, 2023