SKUs are unique product IDs and adding them to the WooCommerce order numbers helps store owners effortlessly manage their inventory. As the sold products are quickly identified using SKU straight from the orders table, it is easy for store owners to update stock levels. Now, let’s see how this WooCommerce customization is implemented via a handy code snippet.
Solution: Add Product SKU to WooCommerce Order Numbers
The code snippet modifies WooCommerce order numbers to include the SKUs of the products in the order.
add_filter( 'woocommerce_order_number', 'ts_add_product_sku_to_order_number', 1, 2 ); function ts_add_product_sku_to_order_number( $order_id, $order ) { // Get order items $items = $order->get_items(); // Extract SKUs from order items $skus = array(); foreach ( $items as $item ) { $product = $item->get_product(); if ( $product ) { $skus[] = $product->get_sku(); } } // Concatenate SKUs with order ID $order_number_with_skus = implode( '-', $skus ) . '-' . $order_id; return $order_number_with_skus; }
Output
The product SKUs are appended to WooCommerce order numbers that helps to quickly identify and track orders.
Do you want to simply track orders and its inventory based on categories? Then you can add product category name to WooCommerce order numbers, that allows store owners to monitor and manage stock levels by category.
Work of genius – I’ve spent more or less all day trying to get the SKUs into the Description line of Stripe and therefore into the statement line that downloads to my accounts package, instead of just the order number, so I don’t have to look up every order number that comes through. Tried three recommended code snippets and none worked. This did it!!
Hi Pete,
Thanks so much for the appreciation! We’re so glad that the code snippet helped you out!