为什么要返回整个计费地址?

发布于 2025-02-12 16:17:48 字数 1066 浏览 0 评论 0原文

我试图最大程度地减少帐单地址,如果“客户已经购买了某些东西或从他的帐户中保存了他的地址”

它有效,但它不呼应地址_2它只是回应了整个计费地址 ,我做错了什么?

//hide billing address from checkout if the address is already entered before
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    if( is_user_logged_in() && has_billing()){
        unset($fields['billing']);
        $fields['billing'] = array();
    }
    return $fields;
}

// Check the meta of Postcode and Country if they are entered.
function has_billing($user_id = false){
            if(!$user_id)
                $user_id = get_current_user_id();

            $shipping_postcode = get_user_meta( $user_id, 'billing_postcode', true );
            $shipping_country = get_user_meta( $user_id, 'billing_country', true );

            // Fetch more meta for the condition has needed.  
            if($shipping_postcode && $shipping_country){
                return $address_fields['address_2']; 
            }           
}

I'm trying to minimize the billing address if the billing address is already entered before "the customer already bought something or saved his address from his account"

It works but it doesn't echo address_2 it just echo the whole billing address
,What I'm doing wrong?

//hide billing address from checkout if the address is already entered before
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    if( is_user_logged_in() && has_billing()){
        unset($fields['billing']);
        $fields['billing'] = array();
    }
    return $fields;
}

// Check the meta of Postcode and Country if they are entered.
function has_billing($user_id = false){
            if(!$user_id)
                $user_id = get_current_user_id();

            $shipping_postcode = get_user_meta( $user_id, 'billing_postcode', true );
            $shipping_country = get_user_meta( $user_id, 'billing_country', true );

            // Fetch more meta for the condition has needed.  
            if($shipping_postcode && $shipping_country){
                return $address_fields['address_2']; 
            }           
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海少女心 2025-02-19 16:17:48

首先,从您的代码来看,尚不清楚如何定义$ adville_fields
根据 https://woocommerce.io.github.io/code-reference/classes/classes/classes/classes/classes/ woocommerce.html

$billing_address_2  = WC()->customer->get_billing_address_2();

First of all, from your code, is not clear how is defined $address_fields
According to https://woocommerce.github.io/code-reference/classes/WooCommerce.html

$billing_address_2  = WC()->customer->get_billing_address_2();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文