ByPass WooFood functionality on Checkout Page for specific products or category
January 20, 2021
TutorialsWooFood
woocommerce food orderingwordpress food ordering plugin
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);