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! 🚀