【问题标题】:Get the Order billing city in WooCommerce email-customer-details.php email template在 WooCommerce email-customer-details.php 电子邮件模板中获取订单计费城市
【发布时间】:2018-01-08 03:41:22
【问题描述】:

我不明白为什么 get_billing_city() 方法在 WC_email customer_details() 方法中不起作用,不像 @ 987654323@ 运行良好。

如何使 get_billing_city()WC_Email customer_details() 方法中工作以在 @987654327 中获得正确的输出@ WooCommerce 模板?

【问题讨论】:

    标签: php wordpress woocommerce orders email-notifications


    【解决方案1】:

    woocommerce 中似乎有一个小错误。

    那么由于它是与订单相关的电子邮件通知,您应该使用 get_billing_country() 方法和 WC_Order 对象。

    对于 WC_Order 对象的 get_billing_country() 方法,这可以通过下面的转向来解决:

    add_filter( 'woocommerce_order_get_billing_country','hook_order_get_billing_country', 10, 2);
    function hook_order_get_billing_country( $value, $order ){
        // Country codes/names
        $countries_obj = new WC_Countries;
        $country_array = $countries_obj->get_countries();
        // Get the country name from the country code
        $country_name = $country_array[ $value ];
        // If country name is not empty we output it
        if( $country_name )
            return $country_name;
        // If $value argument is empty we get the country code
        if( empty( $value ) ){
            $country_code = get_post_meta( $order->get_id(), '_billing_country', true );
            // We output the country name
            return $country_array[ $country_code ];
        }
        return $value;
    }
    

    代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。

    代码经过测试,适用于 wooCommerce 版本 3+

    所以现在你应该让它工作并输出正确的国家/地区名称


    对于 get_billing_country() 方法的 WC_Customer 对象,您应该使用这个:

    add_filter( 'woocommerce_customer_get_billing_country','wc_customer_get_billing_country', 10, 2);
    function wc_customer_get_billing_country( $value, $customer ){
        // Country codes/names
        $countries_obj = new WC_Countries;
        $country_array = $countries_obj->get_countries();
        // Get the country name from the country code
        $country_name = $country_array[ $value ];
        // If country name is not empty we output it
        if( $country_name )
            return $country_name;
        // If $value argument is empty we get the country code
        if( empty( $value ) ){
            $country_code = get_user_meta( $customer->get_id(), 'billing_country', true );
            // We output the country name
            return $country_array[ $country_code ];
        }
        return $value;
    }
    

    代码位于您的活动子主题(或主题)的 function.php 文件中或任何插件文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 2021-11-15
      • 2019-08-05
      相关资源
      最近更新 更多