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.
Print only the SKU
Products without a SKU keep printing their normal name, so nothing ends up blank on the ticket.
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;
}Print the title and the SKU
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.
