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
2 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Pete
3 days 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!!

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