在 Woocommerce 的管理员编辑订单页面上显示客户来源国

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

我希望能够看到产品是从哪个国家订购的,即使它来自原产国。

我想显示原产国的位置:

所以在上图中它确实显示了国家,只要它与商店地址设置的国家不同。

有没有什么方法可以在不破坏自动更新可能性的情况下解除这个限制?

您可以为此使用以下挂钩函数:

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>';
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。