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

How to Add the Country Code to WooCommerce Order Numbers?

Customization to add additional details such as shipping methods, payment methods, or country codes to WooCommerce Order Numbers helps store admins quickly identify the details they want. These details will prevent them from looking into each order’s details. In this post, we will be including the shipping country code directly in the order number which is useful for businesses managing orders from multiple countries or regions. 

Solution: Add the Country Code to WooCommerce Order Numbers

The code snippet retrieves the shipping country code from the order details and appends it to the default order IDs.

add_filter( 'woocommerce_order_number', 'ts_add_shipping_country_code_to_order_number', 1, 2 );

function ts_add_shipping_country_code_to_order_number( $order_id, $order ) {
    // Get shipping country code
    $shipping_country = $order->get_shipping_country();
    $country_code = WC()->countries->get_country_calling_code( $shipping_country );

    // Concatenate country code with order ID
    $order_number_with_country_code = $country_code . '-' . $order_id;

    return $order_number_with_country_code;
}

Output

The output shows that the default order number is modified by appending the shipping country code as a prefix. For example, if the order numbers is ‘1234’ the modified order number would become “+1-1234” according to the shipping country.

How to Add the Country Code to WooCommerce Order Numbers? - Tyche Softwares

If you prefer to track product-related information directly from the orders page, consider the customization of adding product category name to WooCommerce order number. Imagine effortlessly categorizing your orders based on the types of products purchased. This added layer of customization provides valuable data for analyzing sales trends and customer preferences.

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

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x