Skip Navigation

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

Problem:
The client needed to apply a fix for the WooCommerce Stripe Payment Gateway to limit the Stripe SEPA method to EU countries only, but the provided code snippet did not work for multiple countries.
Solution:
We recommended using a modified code snippet that checks against a group of EU countries instead of using multiple if-else statements. Here is the code to use:

// Limit Stripe to a group of EU countries only.<br />add_filter( 'woocommerce_available_payment_gateways', function( $gateways ) {<br />    $country = WCML\MultiCurrency\Geolocation::getUserCountry();<br />    // List of EU country codes<br />    $eu_countries = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK');<br />    if ( $country ) {<br />        // Check if the country is not in the list of EU countries<br />        if ( !in_array($country, $eu_countries) ) {<br />            unset( $gateways['stripe'] );<br />        }<br />    }<br /><br />    return $gateways;<br />} );

We also noted that this code is a helpful adjustment and has not undergone official testing by our team, nor will it be supported by us. We advised the client to ensure they have a complete, working backup of their system before implementation.

Please note that this solution might be irrelevant due to being outdated or not applicable to your case. If this is the case, we highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket.

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 topic contains 4 replies, has 2 voices.

Last updated by ivanE-4 1 year, 2 months ago.

Assisted by: Bobby.

Author Posts
February 12, 2024 at 4:55 pm #15294151

ivanE-4

Hi,

I am opening a new thread as recommended by wpml, regarding this issue :

https://wpml.org/errata/woocommerce-stripe-payment-gateway-country-availability-changes-are-not-saved

My question is how we can apply the fix mentioned but for more than one countries. In our case it's all eu countries.

All eu countries are only allowed for stripe Sepa method.

Trying second country doesn’t seem to work ex:

if ( ‘ES’ !== $country) {
unset( $gateways[‘stripe_sepa’] );
}
elseif ( ‘BG’ !== $country) {
unset( $gateways[‘stripe_sepa’] );
}

Let me know if you need anything from me.

February 12, 2024 at 11:52 pm #15295229

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi,

To ensure I understood correctly, are you looking to exclude all EU countries from using Stripe or only allow specific countries to use it?

Elseif in theory should work as expected, however, you can also as a workaround downgrade the stripe payment gateway plugin to 4.7 see here:
https://wpml.org/forums/topic/changes-dont-saved-on-stripe-settings/#post-10285453

This might also be of help:

If you go to WC->Settings->Payments I believe Stripe also offers an option to enable "Stripe SEPA Direct Debit – SEPA Direct Debit"

SEPA Direct Debit
Customer Geography: France, Germany, Spain, Belgium, Netherlands, Luxembourg, Italy, Portugal, Austria, Ireland.

February 13, 2024 at 2:01 pm #15297956

ivanE-4

Thank you for the assistance!

Unfortunately the link you shared shows to me as Archived, see image. The current stripe gateway version is 7.9.1 see image and going back to 4.7 seems to large jump back.

Yes, SEPA Direct debit is exactly the method in question we need country limited to EU countries.

We would like the SEPA stripe method to be active on all eu countries only.
$countries = ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'];

The elseif code I copied above worked but only for the ES ( the first if statement ) and not on any of the following elseif statements. Checked it also with switch.

If you have any other questions regarding this, glad to reply.
Thank you again.

Screenshot 2024-02-13 155720.png
Screenshot 2024-02-13 155707.png
Screenshot 2024-02-13 155514.png
Screenshot 2024-02-13 155424.png
February 13, 2024 at 7:26 pm #15299298

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Thank you for the screenshots and the detailed explanation 🙂

Looks like I had a typo as I meant to say 5.7, but yes that is still quite a rollback.

Testing the code you shared with me and using the list of countries I rewrote it slightly to check against the group of them rather than the if else if statement.

Please try the following code:

// Limit Stripe to a group of EU countries only.
add_filter( 'woocommerce_available_payment_gateways', function( $gateways ) {
    $country = WCML\MultiCurrency\Geolocation::getUserCountry();
    // List of EU country codes
    $eu_countries = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK');
    if ( $country ) {
        // Check if the country is not in the list of EU countries
        if ( !in_array($country, $eu_countries) ) {
            unset( $gateways['stripe'] );
        }
    }

    return $gateways;
} );

I have tested it locally for me and Stripe is not provided as an option. I am based in the US.

NOTE: The code provided is intended as a helpful adjustment to an existing workaround suggested by our team. It has not undergone official testing by our team, nor will it be supported by us. Please use this code for further testing of the issue you're encountering, and ensure you have a complete, working backup of your system before implementation.

Let me know your results, please.

February 15, 2024 at 4:10 pm #15308581

ivanE-4

Just wanted to confirm for anyone who needs it, this worked now. I only changed the method to stripe sepa instead.
Thank you very much for your assistance!