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_.
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_softwarefilter, 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 returnsfalseand 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.
