I have this code that adds the product name as a prefix to the order number via functions.php, but I want to change it to add the SKU. Also, it would be nice if the quantity for each SKU could be inserted at the same time.
Similar to: 2xSKUA_1xSKUB_Order number
Can anyone point me in the right direction?
function filter_woocommerce_order_number( $this_get_id, $instance ) { $order = new WC_Order( $this_get_id ); $items = $order->get_items(); foreach ( $items as $item ) { $product_name = preg_replace('/\s+/', '_', $item['name']);; break; } $new_id = $product_name.'_'.$this_get_id; return $new_id; }; add_filter( 'woocommerce_order_number', 'filter_woocommerce_order_number', 10, 2 );
To add SKU before the quantity of the order items (products), use it after the order number. Code revisited below:
It should work as you expect.