WPSlash Licences

Print the Product SKU Instead of the Title in FoodMaster Automatic Order Printing

Print the Product SKU Instead of the Title in FoodMaster Automatic Order Printing – code snippet guide from WPSlash
Published
Updated
Reading time
2 minutes
Written by
WPSlash team

Long product names take up a lot of space on a kitchen ticket. Many restaurants give each dish a short code instead, such as P12 for a large pepperoni, and want that code on the printed order. In WooCommerce that code lives in the product’s SKU field. This guide shows how to make the FoodMaster (formerly WooFood) automatic order printing software print the SKU instead of the product title, or next to it.

How it works

The printing software reads each order from the FoodMaster REST API. Before every line item is sent, FoodMaster passes its name through the foodmaster_rest_line_item_name filter, together with the product ID. Hooking into that filter changes what is printed on the ticket without touching the name customers see on your website, in the cart or in order emails.

Note for older installs: earlier WooFood versions used the filter name woofood_rest_line_item_name. On current FoodMaster versions use foodmaster_rest_line_item_name, as in the examples below.

Step 1: give your products a SKU

In WordPress go to Products, edit a product and open the Inventory tab of the Product data box. Enter the short code in the SKU field and update the product. Do this for every product you want printed by code.

Step 2: add the code snippet

Add one of the snippets below to the functions.php file of your child theme, or use a code snippets plugin, so the change survives theme updates.

Products without a SKU keep printing their normal name, so nothing ends up blank on the ticket.

Code
add_filter( 'foodmaster_rest_line_item_name', 'wpslash_print_sku_instead_of_title', 10, 2 );

function wpslash_print_sku_instead_of_title( $product_name, $product_id ) {
	$product = wc_get_product( $product_id );
	if ( $product && $product->get_sku() ) {
		return $product->get_sku();
	}
	return $product_name;
}
Code
add_filter( 'foodmaster_rest_line_item_name', 'wpslash_print_title_and_sku', 10, 2 );

function wpslash_print_title_and_sku( $product_name, $product_id ) {
	$product = wc_get_product( $product_id );
	if ( $product && $product->get_sku() ) {
		return $product_name . ' [' . $product->get_sku() . ']';
	}
	return $product_name;
}

Use only one of the two snippets at a time.

Step 3: test with a new order

Place a test order and let the printing software pick it up. The ticket should now show the SKU. If it still shows the title, check that the product really has a SKU and clear any page or object cache. Variable products use the SKU of the chosen variation when the variation has its own SKU.

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