This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This thread is resolved. Here is a description of the problem and solution.

Problem:

Compatibility issue with Amazon pay in checkout of free orders.

https://woocommerce.com/products/pay-with-amazon/

Solution:

The problem seems to be in this file:
/wp-content/plugins/woocommerce-gateway-amazon-payments-advanced/includes/compats/class-wc-amazon-payments-advanced-woocommerce-multilingual-compat.php

where the author added this condition:

    public function maybe_restore_subtotal( $cart ) {
        if ( ! class_exists( 'woocommerce_wpml' ) ) {
            return;
        }

        if ( ! defined( 'WC_DOING_AJAX' ) || ! WC_DOING_AJAX ) {
            return;
        }

        // WCML sets cart->needs_payment() to become `false`.
        add_filter( 'woocommerce_cart_needs_payment', '__return_true' );
    }

So it always returns payment is needed when WCML is active and is doing Ajax. And that's why the message appears.

If we add another condition to check if the cart is zero, it works.
So, in that file replace:

        // WCML sets cart->needs_payment() to become `false`.
        add_filter( 'woocommerce_cart_needs_payment', '__return_true' );
    }

With:

        // WCML sets cart->needs_payment() to become `false`.
        if ( (float)WC()->cart->cart_contents_total != 0) {
            add_filter( 'woocommerce_cart_needs_payment', '__return_true' );
        }

That worked for me. Can you please check it on your site?

**** Important! Please make a full site backup (files and DB) before you proceed with those steps****

Relevant Documentation:

This topic contains 14 replies, has 2 voices.

Last updated by arminF-2 1 year, 1 month ago.

Assigned support staff: Itamar.

Author Posts
August 4, 2018 at 8:48 am #2612495

arminF-2

I am trying to:
Some of our orders in Woocommerce are free of charge (total 0,00). In this case Woocommerce does not ask for a payment gateway in checkout.
Now I realised that when I have Woocommerce Multilingual + Amazon Pay activated (amazon pay does not need to be enabled) this option does no longer work and I get the following message during checkout: "Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements."

Link to a page where the issue can be seen:
hidden link (buy and go to checkout)

August 5, 2018 at 9:25 am #2613535

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi.

Thank you for contacting the WPML support forum.

I cannot see the issue on your site because it is not available now.
I get the DNS_PROBE_FINISHED_NXDOMAIN error.

I understand that the Amazon pay is a plugin.
Is it correct?
Can you please share with me the link to this plugin's page?

To ensure the quickest and most accurate support, please provide your debug information so that I can get a look at some of your configurations.
We have an excellent article on how to located here: https://wpml.org/faq/provide-debug-information-faster-support/.

Thanks,
Itamar.

August 5, 2018 at 11:58 am #2613601

arminF-2

Hi Itamar,

sorry for the partial information.
The amazon plugin can be received free of charge here: https://woocommerce.com/products/pay-with-amazon/

Locally I also updated to the latest woocommerce multilingual version, but that did not change the observed behaviour at all.

Best
Armin

August 5, 2018 at 3:02 pm #2613774

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, Armin and thanks for attaching the debug information.

You are writing to me here that you have updated WooCommerce Multilingual to its latest version. Is it indeed updated to the latest version? The debug information shows that WPML and all its add-ons are not updated to their latest version. Also, WooCommerce and WordPress itself are slightly not updated. Can you please update everything and see if the problem persists? This would be the first debugging procedure and might solve the issue.

Thanks,
Itamar.

August 5, 2018 at 3:22 pm #2613794

arminF-2

Hi,

yes. Locally on my development site this has been tested without any effect on the issue.
I can not deploy this live yet, as there needs to be more testing if any of the changes will affect our shop.
Therefore the debug info from the live site does not reflect the latest updates.

Best Regards

August 5, 2018 at 3:49 pm #2613802

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

OK, I see, Armin.

As I've mentioned, I cannot see your dev site here hidden link.
Can I also see the issue on your live site?
If so can you please send me the link to the free product where I can see the issue?

Thanks,
Itamar.

August 5, 2018 at 3:56 pm #2613804

arminF-2

Hi,

you can find the site here: hidden link
and please use coupon allfree on any product to get it to 0€.

Best Regards

August 5, 2018 at 4:14 pm #2613843

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Thanks.

I currently see only shortcodes and I can use the site to see the problem. Please see the attached screenshot. Can you please fix it?

Thanks,
Itamar.

August 5, 2018 at 4:19 pm #2613855

arminF-2

Hi,

the top navigation is fully usable (I deactivated many plugins and the theme that would make the frontpage work).
Please choose any product from the navigation menu.

August 6, 2018 at 4:18 pm #2616680

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi and thanks for the extra details.

I can see the issue on your site.
In fact, I can reproduce the issue on a clean WordPress installation.
It is important for me to mention that the Amazon Pay is not officially compatible with WooCommerce Multilingual. In any case, I've escalated this issue to our compatibility team to see if they can find a solution for this issue. It might be that the cooperation of the plugins' author will be needed.

I'll keep you update here of any news about this issue.

Regards,
Itamar.

August 10, 2018 at 2:15 pm #2634298

arminF-2

Hi Itamar,

thanks for confirming and escalating this.
Do you know if they had the chance to look into this and what a usual timeline for a patch would be?

Best Regards
Armin

August 13, 2018 at 10:02 am #2639455

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, Armin.

I've sent a note to our compatibility team that you are inquiring about this issue, and I'm waiting for their reply.

I'm sorry, but I have no way to know how much time it will take a workaround for this issue.
It might involve the cooperation of the author of the plugin.

I'll keep you updated here on any news.

Best Regards,
Itamar.

August 16, 2018 at 4:45 pm #2650757

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, Armin.

Update
Our second tier has found a fix for this issue and we are waiting for our developer approval about it. I'll share it with you once I get it.

August 23, 2018 at 10:01 pm #2671696

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, Armin.

The problem seems to be in this file:
/wp-content/plugins/woocommerce-gateway-amazon-payments-advanced/includes/compats/class-wc-amazon-payments-advanced-woocommerce-multilingual-compat.php

where the author added this condition:

    public function maybe_restore_subtotal( $cart ) {
        if ( ! class_exists( 'woocommerce_wpml' ) ) {
            return;
        }

        if ( ! defined( 'WC_DOING_AJAX' ) || ! WC_DOING_AJAX ) {
            return;
        }

        // WCML sets cart->needs_payment() to become `false`.
        add_filter( 'woocommerce_cart_needs_payment', '__return_true' );
    }

So it always returns payment is needed when WCML is active and is doing Ajax. And that's why the message appears.

If we add another condition to check if the cart is zero, it works.
So, in that file replace:

        // WCML sets cart->needs_payment() to become `false`.
        add_filter( 'woocommerce_cart_needs_payment', '__return_true' );
    }

With:

        // WCML sets cart->needs_payment() to become `false`.
        if ( (float)WC()->cart->cart_contents_total != 0) {
            add_filter( 'woocommerce_cart_needs_payment', '__return_true' );
        }

That worked for me. Can you please check it on your site?

**** Important! Please make a full site backup (files and DB) before you proceed with those steps****

Regards,
Itamar.

August 25, 2018 at 6:54 pm #2675494

arminF-2

Hi,
I can confirm that this fix works for me.
I previously had the whole filter removed as I didn't see any negative effects from removing it.

Thanks for your help