WPSlash

ByPass WooFood functionality on Checkout Page for specific products or category

Wednesday January 20, 2021

The following example will exclude the products you will specify in $exluded_ids from WooFood functionality

function wpslash_conditionally_disable_woofood_functionality($true)
{

    global $woocommerce;

    $exluded_ids = array(1941, 134);
if(WC()->cart && !is_admin())
	{
    foreach( WC()->cart->get_cart() as $cart_item ){
        $product_id= $cart_item['product_id'];

        if( in_array($product_id, $exluded_ids))
        {
            
            return false;
        }
    }
}
    return $true;

}
add_filter("woofood_core_functionality_enabled", "wpslash_conditionally_disable_woofood_functionality", 10, 1);

If you want to exclude a whole category from WooFood functionality you can use the following code snippet

function wpslash_conditionally_disable_woofood_functionality($true)
{

    global $woocommerce;

    $exluded_cats = array(25);
if(WC()->cart && !is_admin())
	{
    foreach( WC()->cart->get_cart() as $cart_item ){
        $product_id= $cart_item['product_id'];
        $product_terms = get_the_terms( $product_id , 'product_cat' );
		$cat_ids = array();
		 foreach ($product_terms as $term_cat) { 
   			 $cat_ids[]= $term_cat->term_id; 
    
			}


        if( in_array($cat_ids[0], $exluded_cats))
        {
            
            return false;
        }
    }
}
    return $true;

}
add_filter("woofood_core_functionality_enabled", "wpslash_conditionally_disable_woofood_functionality", 10, 1);

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