Home > other >  Why return echo the whole billing address?
Why return echo the whole billing address?

Time:07-05

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

CodePudding user response:

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();

  • Related