Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Add Product SKU to WooCommerce Order Numbers?

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.

How to Add Product SKU to WooCommerce Order Numbers? - Tyche Softwares

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.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Pete
5 months ago

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!!

0
Would love your thoughts, please comment.x
()
x
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible.

Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

By using our site, you acknowledge that you have read and understood our Privacy Policy and Terms & Conditions.