WPSlash

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

Wednesday March 8, 2023

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 Automate Product Re-Enabling in WooFood?

✔ Prevent manually updating disabled products every day
✔ Ensure that all food items are available for ordering at the start of each business day
✔ Avoid customer confusion when products remain unavailable due to auto-disable settings

How to Set Up a Daily Cron Job to Re-Enable Products in WooFood

To automate this process, insert the following PHP snippet into your theme’s functions.php file or inside a custom plugin:



add_action("init", "schedule_daily_reset_wpslash");

function schedule_daily_reset_wpslash()
{
	if(!wp_next_scheduled('re_enable_products_every_day'))
	{
			wp_schedule_event( strtotime('05:20:00'), 'daily', 're_enable_products_every_day' );

	}

}
add_action("re_enable_products_every_day", "re_enable_products_every_day");

function re_enable_products_every_day()
{
	
	global $woocommerce;
	$all_products = wc_get_products(array("limit"=>-1, 'return'=>'ids' ));
	
	foreach($all_products as $product_id)
	{
		update_post_meta($product_id, 'woofood_product_availability', false);
	}
}

How This Code Works

✅ The function schedule_daily_reset_wpslash() checks if a cron job is already scheduled. If not, it schedules a daily event at 5:20 AM.
✅ The re_enable_products_every_day() function retrieves all WooCommerce products and resets their woofood_product_availability meta field.
✅ This ensures that all disabled products are automatically re-enabled at the start of each day.

Best Practices for Using This WooCommerce Automation

🔹 Ensure your WordPress cron jobs are running properly (some hosting providers disable them).
🔹 Modify the scheduled time (05:20:00) to match your business hours.
🔹 Test the script on a staging environment before applying it to your live site.

Looking for a More Advanced WooCommerce Food Ordering System?

Managing food orders manually can be overwhelming, especially when handling pickup and delivery orders. Instead of managing product availability manually, use WooFood – WooCommerce Food Delivery Plugin for a fully automated restaurant ordering system.

With WooFood, you can:
✅ Automate order processing for pickup and delivery
✅ Set custom availability rules for food items
✅ Improve the checkout experience with real-time order management

👉 Check out WooFood here to streamline your WooCommerce restaurant ordering process today! 🚀

Leave a Comment

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

Related Articles

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 Add Live Product Search to WooFood in WooCommerce

Enhancing the user experience of your WooCommerce-powered restaurant ordering system is crucial, and adding a live product search feature can significantly improve navigation. This feature allows customers to quickly find food items in your WooFood-powered menu without manually browsing through categories. In this article, we’ll show you how to integrate a live product search above the accordion menu in WooFood using a simple jQuery script and PHP snippet. […]
December 29, 2022
Tutorials WooFood

How to Disable Actions and Show an Overlay When Your WooCommerce Store is Closed

If you’re running a WooCommerce restaurant ordering system, you may want to disable ordering and display an overlay when your store is closed or not accepting orders. This ensures that customers know when ordering is unavailable, improving the user experience. In this guide, we’ll show you how to use a simple PHP snippet to automatically disable WooCommerce orders and display an overlay notification when the store is […]
June 2, 2022