Skip Navigation

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

Problem:
During checkout payment gateways are displayed even when the total amount is 0 (only free products in the cart). In this case the problem was due to a conflict with the WooCommerce Amazon Pay plugin.

Solution:
We have identified a conflict between WooCommerce Multilingual (WCML) and the WooCommerce Amazon Pay plugin. As a temporary workaround, you can edit the WooCommerce Amazon Pay plugin code. Here are the steps:

1. Navigate to the file

wp-content/plugins/woocommerce-gateway-amazon-payments-advanced/includes/compats/class-wc-amazon-payments-advanced-woocommerce-multilingual-compat.php

.
2. Locate the function

maybe_restore_subtotal

around line 22.
3. Replace the existing code of that function with the following:

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

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

	if ( WC()->cart->total == 0) {
		return;
	}

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

We will also contact the plugin authors to incorporate this solution. Meanwhile, you can encourage them to join the WPML Go Global program.

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.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Nigel 6 months ago.

Assisted by: Nigel.

Author Posts
October 20, 2023 at 5:19 pm #14626243

Anja

Tell us what you are trying to do?

We are using WooCommerce Multilingual & Multicurrency plugin for our multilingual shop. We have some free products and if a customer wants to order only free products the payment gateways are displayed. Which is not normal behaviour with a total amount of 0. They should be able to go straight to confirming the order without having to choose a payment gateway.

We deactivated several plugins and noted that the error doesn't occur with Woo Multilingual plugin deactivated. It worked until last week, and it all works fine with the plugin activated and products with a price. The problem arises only with free products.

We tried version 5.2.0 and 5.2.1, but no difference.

What is the link to your site?
hidden link

October 23, 2023 at 12:16 pm #14637941

Nigel
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Hi there

I can see the issue on your site, if I add a free product to the basket and go to the checkout.

I set up a test on my own local site and I can't reproduce the problem, I don't get the payment gateway section for free products, in either the original language or translated pages, so it looks like it may be related to something quite specific on your site.

Do you have a staging site available where I can perform some basic tests, including de-activating/re-activating plugins and switching settings?

Let me mark your next reply as private so that I can get log-in credentials for it from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site.

October 24, 2023 at 3:39 pm #14649403

Nigel
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Sorry! It says the username you provided is not registered on the site.

Could you please check?

You can edit your previous reply and update the credentials.

Screenshot 2023-10-24 at 16.37.35.png
October 24, 2023 at 4:23 pm #14649665

Anja

Oh sorry, typing error 🙂

Please try 'wmpl' or email noreply@wpml.org

October 25, 2023 at 10:18 am #14659603

Nigel
Supporter

Timezone: Europe/Madrid (GMT+02:00)

Thanks for clarifying.

I ran some tests on your site, and I determined that the problem arises because of a conflict between WCML and the WooCommerce Amazon Pay plugin. Disable either plugin and the message is no longer displayed for free products.

I have escalated this to our Compatibility team so that they can investigate further, and I'll keep you posted with any feedback they have.

October 31, 2023 at 10:21 am #14698333

Nigel
Supporter

Timezone: Europe/Madrid (GMT+02:00)

My colleague identified where the issue arises, in the code of the WooCommerce Amazon Pay plugin.

We can suggest an edit that you can make to their plugin to use as a workaround to fix the issue, which I share below.

Our compatibility team will try to contact the plugin authors about incorporating the solution, but it may also help if you contact them, and invite them to join the WPML Go Global programme, directing them to https://wpml.org/documentation/support/go-global-program/

The edit you can make is to the file wp-content/plugins/woocommerce-gateway-amazon-payments-advanced/includes/compats/class-wc-amazon-payments-advanced-woocommerce-multilingual-compat.php.

Around line 22 you will see the function maybe_restore_subtotal declared.

Replace the existing code for that function with this:

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

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

		if ( WC()->cart->total == 0) {
			return;
		}

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

That should resolve the problem for now. (If they update the plugin without making this change you may need to re-apply the above workaround.)

Anja confirmed that the issue was resolved on 2023-11-01 16:36:03.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.