Search code examples
phpwordpresswoocommerceorderscountry

Display the customer origin country on admin edit order pages in Woocommerce


I would like to be able to see which country the product was ordered from, even if it is from the origin country.

The location where I would like to show the origin country:

text So in the picture above it does show the country as long as it is not the same country as the country the store address is set to.

Is there any way to remove this limitation without ruining the possibility for automatic updates?


Solution

  • You can use the following hooked function for that:

    add_action( 'woocommerce_admin_order_data_after_shipping_address', 'ordered_origin', 10, 1 );
    function ordered_origin( $order ){
        $country_code = $order->get_shipping_country();
        $wc_countries = WC()->countries;
    
        // Get the shipping coutry code
        $shipping_country_name = $wc_countries->countries[$country_code];
    
        echo '<p><strong>'.__('Ordered origin').':</strong> ' . $shipping_country_name . '</p>';
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.