Skip Navigation

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

Problem:
The client is experiencing an issue where the "Products" filter in the Smart Coupons settings is not being applied in a second language.
Solution:
If you're encountering this issue, we recommend you take the following steps:
1. Please make a full website backup.
2. Completely remove any Coupon Translation you have (change the language in the top bar, move the translation to the trash, and then permanently delete them).
3. Go to WPML > Settings and set "shop_coupon" as not translatable.
4. In your functions.php file, add the following code at the end:

add_filter('woocommerce_coupon_get_wc_sc_add_product_details', 'testing_coupon_discount_after_adding_to_cart');

function testing_coupon_discount_after_adding_to_cart($var) {<br />    foreach ($var as $key => $prod ) {<br />    $my_current_lang = apply_filters( 'wpml_current_language', NULL );<br />        $type = get_post_type($prod["product_id"]);<br />        $translations = apply_filters( 'wpml_get_element_translations', NULL, $prod["product_id"], 'post_'. $type );<br />    $var[$key]["product_id"] = $translations[$my_current_lang]->element_id;<br />    }<br />    return $var;<br />}

5. Save the changes.
This should make the coupon work in both languages. It's not necessary to translate the coupon; just create it in the default language.

Please note that this solution might be irrelevant if it's outdated or not applicable to your case. We highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, 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.

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by Lucas Vidal de Andrade 1 month ago.

Assisted by: Lucas Vidal de Andrade.

Author Posts
April 10, 2024 at 11:51 am #15504402

maartenv-15

The client is having an issue, where the "Products" filter in the Smart Coupons settings, is not being applied in a second language.

There is this similar ticket:
https://wpml.org/forums/topic/coupon-dosent-work-for-other-language-2/

The difference is that the user in the Ticket was using the "Exclude Products" field, whereas here the client is using the "Products" field. The client stated that the solution did not work for him, but that would need further investigation.

April 11, 2024 at 12:03 pm #15508965

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

Thank you for your patience, our queue has been quite high as of lately. I would like to analyze a copy of your website.

I would like to request temporary access (wp-admin and FTP) to your site to take a better look at the issue. It would be better to a testing site where the issue is replicated.

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Maybe I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” or "All in One WP Migration" on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok with you.

IMPORTANT

- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this:

hidden link

April 18, 2024 at 1:39 pm #15539197

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

I checked the staging version you sent, and noticed that the plugins are really outdated. Can you please update them to the latest version? Please note that you might have to create a website key for the staging version on wpml.org, so you can update WPML and related plugins.

About the issue itself:

1. When adding the coupon in the EN version, the product is added but the discount to it is not applied;
2. The product filter is working in EN (I tried applying the coupon with non valid products in the cart and was blocked, as expected);

So, the issue is only that the discount is not applied to the product added by the coupon. Can you confirm that?

As soon as you update the plugins, I'll continue with the support.

April 23, 2024 at 9:11 am #15554569

maartenv-15

Hi,

- When using the coupon on EN language it works fine -> it adds 1 free product to cart.
When using the coupon on NL language the coupon won't work -> because the included products which are selected for the coupon are EN products (and not the NL translated) products. So if i also can select the NL translated products for include and add free product this would solve my issue.

- All plugins have been updated.

Regards,

Maarten

April 23, 2024 at 4:23 pm #15557451

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

Thank you for sharing that. I was able to tweak some of the settings, so we could manually translate the coupons. That allows us, in theory, to create a translation into NL from scratch. Please make a full website backup and follow these steps:

1. In WPML > Settings > Custom Fields Translation, search for "wc_sc" and mark all results as "Translate" (see image 01);
2. In WPML > Settings > Post Type Translation, mark "Coupons (shop_coupon)" as "Translatable - only show translated items" (see image 02);
3. In WPML > Settings > Taxonomies Translation, mark "Coupon categories (sc_coupon_category)" as "Translatable - use translation if available or fallback to default language"(see image 03);

Now, when editing the coupon in EN, you should be able to add a translation to it (see image 04). Let me know if that solves the issue for you;

04.jpeg
03.jpeg
02.jpeg
01.jpeg
April 24, 2024 at 9:49 am #15559840

maartenv-15

Thanks, but now the coupon code is not working anymore for the main (EN) language, see screenshots. For NL language the (translated) coupon does work.

EN.png
NL.png
April 24, 2024 at 12:41 pm #15560816

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey Maarten,

The coupons need to have different names, otherwise there'll be conflicts. Please tell me if using the coupons like this is a viable options for you. I renamed the FUNGKIWELCOME to FUNGKIWELCOME-EN in English, so you can see how that would look like action.

If this solution does not suffice, I can reach out to our development team, to check if they have any workarounds. That might take a while, so please let me know what's the best solution for you 🙂

April 24, 2024 at 11:03 pm #15562864

maartenv-15

Sorry, but we need 1 coupon working for both languages. We use the coupon on socials, newsletters and it should not matter which language is used, the coupon should work for all languages. Thanks again.

April 30, 2024 at 7:13 am #15579559

maartenv-15

Ok, i installed the plugin and created 2 products (Product 1 and Product 2) and a similar coupon (= Coupon). Thanks again!

April 30, 2024 at 9:33 pm #15582847

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

By manually translating the coupon in the Sandbox environment I sent you, the coupon worked as expected. I forwarded your staging website to our developers, so they can take a look and find out why it's not behaving the same in your environment. I deactivated all plugins and your theme in the staging version. Please leave it as it is, at least for a few days, so we can look the issue isolated.

As soon as I have feedback from them, I'll let you know. Thank you for cooperating 🙂

May 17, 2024 at 7:27 pm #15640864

Lucas Vidal de Andrade
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

Thank you for your patience. It actually took us a while to figure out how to achieve your desired result. Please make a full website backup and follow these steps:

1. Completely remove any Coupon Translation you have (change the language in the top bar, move the translation to the trash, and then permanently delete them);
2. Go to WPML > Settings and set "shop_coupon" as not translatable;
3. In your functions.php file, add the following code at the end:

add_filter('woocommerce_coupon_get_wc_sc_add_product_details', 'testing_coupon_discount_after_adding_to_cart');

function testing_coupon_discount_after_adding_to_cart($var) {
foreach ($var as $key => $prod ) {
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
$type = get_post_type($prod["product_id"]);
$translations = apply_filters( 'wpml_get_element_translations', NULL, $prod["product_id"], 'post_'. $type );
$var[$key]["product_id"] = $translations[$my_current_lang]->element_id;
}
return $var;
}

4. Save;

That should make the coupon work in both languages. Please note that it's not necessary to translate the coupon. Just create it in the default language. Let me know if that works for you.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.