最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Wrong Billing Information in WC_Checkout->get_checkout_fields('billing')?

programmeradmin2浏览0评论

Anyone know why this could be?

in woocommerce/checkout/form-billing.php brings in WC_Checkout as $checkout

    $fields = $checkout->get_checkout_fields( 'billing' );
    foreach ( $fields as $key => $field ) {
        $formvalue = $checkout->get_value( $key );
        var_dump($key);
        var_dump($formvalue);
        woocommerce_form_field( $key, $field, $formvalue );
    }

bringing in the wrong billing address

string(17) "billing_address_1" string(13) "7198 Maple St"

city state postcode ... only the name is correct for the Billing Address, it seems.

The rest of these values are from the Shipping Address values.

I know the proper values are in for my Billing Address as, on the same page, I performed this at the top:

$fields = $checkout->get_checkout_fields( 'billing' );
$user_id = get_current_user_id();
if ( is_user_logged_in() )
{
    $billingaddress1 = get_user_meta( $user_id, 'billing_address_1', true );
    printr($billingaddress1);
}

And that does bring back, the correct billing_address_1 that should be my form value from get_checkout_fields( 'billing' )

Been struggling with it for a while now, it doesn't make any sense to me.

Anyone know why this could be?

in woocommerce/checkout/form-billing.php brings in WC_Checkout as $checkout

    $fields = $checkout->get_checkout_fields( 'billing' );
    foreach ( $fields as $key => $field ) {
        $formvalue = $checkout->get_value( $key );
        var_dump($key);
        var_dump($formvalue);
        woocommerce_form_field( $key, $field, $formvalue );
    }

bringing in the wrong billing address

string(17) "billing_address_1" string(13) "7198 Maple St"

city state postcode ... only the name is correct for the Billing Address, it seems.

The rest of these values are from the Shipping Address values.

I know the proper values are in for my Billing Address as, on the same page, I performed this at the top:

$fields = $checkout->get_checkout_fields( 'billing' );
$user_id = get_current_user_id();
if ( is_user_logged_in() )
{
    $billingaddress1 = get_user_meta( $user_id, 'billing_address_1', true );
    printr($billingaddress1);
}

And that does bring back, the correct billing_address_1 that should be my form value from get_checkout_fields( 'billing' )

Been struggling with it for a while now, it doesn't make any sense to me.

Share Improve this question asked Jul 4, 2020 at 0:57 Brian BrumanBrian Bruman 1251 silver badge10 bronze badges 1
  • I guess this is a caching issue of some sort? I registered a brand new user with completely seperate billing and shipping addresses and they both returned properly – Brian Bruman Commented Jul 4, 2020 at 1:15
Add a comment  | 

1 Answer 1

Reset to default 0

Update Your get_checkout_fields method with parameter billing_country
so it will look like
$fields = $checkout->get_checkout_fields( 'billing_country' );
Documentation:
https://docs.woocommerce/wc-apidocs/source-class-WC_Checkout.html#197-281

发布评论

评论列表(0)

  1. 暂无评论