Billing Details Fields Error | WordPress.org

[ad_1]

Hi @ashour

There isn’t anything in this plugin’s code that assigned a value of “undefined” to the address fields. “Undefined” usually indicates a value is being changed by Javascript on your checkout page.

I’d recommend checking other plugins that you have installed to see if they are causing that behavior. I have seen where cache plugins can cause that behavior.

Kind Regards,

Thread Starter
ashour

(@ashour)

Hi,

hmm… It doesn’t happen with the “Paypal Standard” gateway but happens with yours!

Can you please double check?

Regards!

Hi @ashour

hmm… It doesn’t happen with the “Paypal Standard” gateway but happens with yours!

We have a lot of merchants using this plugin and if it was a widespread issue with the plugin we’d be getting a lot of reports. I am also not able to reproduce your described issue on our development site.

Can you share a website url where this can be re-created? If the website can be placed in sandbox mode that’s the best for testing purposes.

Thanks,

Thread Starter
ashour

(@ashour)

Ok, It seems I had to check it myself in order to believe me :D.

here is the problem:
pymntpl-paypal-woocommerce/src/AjaxFrontendHandler.php : 50 ( private function get_update_data() )

You guys filter the checkout posted data. the problem is you hardcode these fields instead of using get_checkout_fields() function. specifically inside the condition ( if ( Utils::is_valid_address( $address ) ) { ) : line 72

It will work with “a lot of merchants” because they use the default fields as it is, but If someone like me don’t need some of these fields, It will fail like in “screenshots attached” with “undefined” value which is set by your plugin.

Kind Regards!

Hi @ashour

You guys filter the checkout posted data. the problem is you hardcode these fields instead of using get_checkout_fields() function. specifically inside the condition ( if ( Utils::is_valid_address( $address ) ) { ) : line 72

We don’t hardcode the fields, we map the Payer’s address to the $data associative array. Using the WC_Checkout::get_checkout_fields function wouldn’t make sense in that section of code.

It will work with “a lot of merchants” because they use the default fields as it is, but If someone like me don’t need some of these fields, It will fail like in “screenshots attached” with “undefined” value which is set by your plugin.

Can you please elaborate on what you mean by “don’t need some of these fields”. Are you removing WooCommerce Checkout fields using filters so they aren’t visible on the checkout page? If so, what fields exactly?

I would need to have you explain what your setup is to try and re-create what you’re describing.

Thanks

Thread Starter
ashour

(@ashour)

I use woocommerce_checkout_fields filter in order to remove checkout billing fields that I don’t need.

So, for example If you removed the “postal code” field using this filter. Your plugin will force setting it in the function mentioned above using this line:
$data["{$prefix}postcode"] = $address->getPostalCode();

which returns undefined in this case because the field doesn’t exist in the submitted fields.

After debugging, the issue is caused because of the following reasons:

  1. When you unset a field using filter woocommerce_checkout_fields, that doesn’t prevent WooCommerce from calling $('#billing_state).val(), $('#billing_address_1).val() etc when the update_order_review event is triggered on the checkout page.
  2. As a result, the $_POST object is populated with values of undefined because anytime jQuery is used to fetch an element value that doesn’t exist, it returns “undefined”.
  3. This results in WooCommerce populating the WC_Customer object with values of “undefined” in the WC_Ajax::update_order_review function.
  4. When the order is submitted, the Utils::is_valid_address( $address ) line of code returns true in class AjaxFrontendHandler because all of the address fields have a valid string value of “undefined” which has a string length greater than one.

We will have to make a change to account for the fact that WooCommerce sends a value of “undefined” to the server even when the field doesn’t exist and “undefined” is a legitimate string.

Thanks

You can use our contact us page if you want to use the updated version.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer