WPSlash Licences

Conditionally Exclude Orders from Automatic Printing in WooCommerce

How to Conditionally Exclude Orders from Automatic Printing in WooCommerce – code snippet guide from WPSlash
Published
Updated
Reading time
1 minutes
Written by
WPSlash team

This snippet stops FoodMaster (formerly WooFood) from sending an order to the automatic printing software when the order contains a gift card. Add it to your child theme’s functions.php file, or to a code snippets plugin.

Exclude gift card orders from automatic printing

Updated for current FoodMaster versions: the code below uses the foodmaster_ names. Older installs that still run WooFood used the woofood_ prefix, so on those change foodmaster_ back to woofood_.

Code
add_filter("foodmaster_rest_include_order_in_software", "wpslash_exclude_order_from_software", 10, 2);
function wpslash_exclude_order_from_software($bool, $order_data)
{
	global $woocommerce;
	foreach ( $order_data["line_items"] as $line_item ) {
   $product_id = intval($line_item['product_id']);
 	$product = wc_get_product($product_id);
		
		if ($product->is_type('gift-card')) {
        	return false;


    }
}
	return $bool;
}

How the snippet works

  • It hooks into the foodmaster_rest_include_order_in_software filter, which decides whether an order goes to the printing software.
  • It loops over the order’s line items and loads each product with wc_get_product().
  • If a product is of type gift-card, it returns false and the order is not printed.
  • For every other order it returns the value it was given, so the order prints as usual.

To check it worked, place a test order with a gift card and another with a normal menu item. The gift card order should stay out of the printer queue and the food order should print.

FoodMaster (formerly WooFood)

The snippet uses a filter from FoodMaster (formerly WooFood), the restaurant ordering plugin for WooCommerce. You can get FoodMaster here.

FoodMasterRestaurant ordering for WooCommerce: delivery, pickup and dine-in, a POS for counter and phone orders, a kitchen display and automatic ticket printing. Used by 10,000+ restaurants.$499 for one site
All guides

FoodMaster (formerly WooFood)12 min read

Best Store Address Setup for Pickup

Compare single-address, multi-location, and directions-first pickup setups to reduce wrong-door visits and simplify checkout.

The plugins these guides are about

FoodMaster for restaurants, courier vouchers for the Greek market, marketplace sync and store tools, all for WooCommerce.

Browse plugins30-day money-back on every plugin