Translate the coupon message with a shortcode #
Coupon by User Role for WooCommerce includes one shortcode, [alg_wc_cbur_translate], for showing the “Coupon is not valid” message in the visitor’s language. It works inside the message field because that field runs shortcodes.
Where to use it #
Go to WPFactory > Coupon by User Role (also reachable at WooCommerce > Settings > Coupon by User Role), open the Availability section, and put the shortcode in the “Coupon is not valid” message field.
Requirements #
The shortcode reads the active language from the WPML constant ICL_LANGUAGE_CODE. It works on WPML, and on Polylang setups that define this constant. If neither is active, the shortcode simply falls back to its default text, so it is safe to leave in place on a single-language store.
Two ways to write it #
1. Inline attributes #
Pass the language, the text for that language, and the fallback text as attributes:
[alg_wc_cbur_translate lang="DE" lang_text="Gutschein ist fuer deine Benutzerrolle nicht gueltig." not_lang_text="Coupon is not valid for your user role."]
lang: one or more language codes, comma separated (for exampleDEorDE,NL).lang_text: shown when the active language matcheslang.not_lang_text: shown for every other language.
2. Enclosing tags #
Wrap each language’s text between opening and closing tags, and use not_lang for the fallback:
[alg_wc_cbur_translate lang="DE"]Gutschein ist fuer deine Benutzerrolle nicht gueltig.[/alg_wc_cbur_translate]
[alg_wc_cbur_translate lang="NL"]Coupon is niet geldig voor jouw gebruikersrol.[/alg_wc_cbur_translate]
[alg_wc_cbur_translate not_lang="DE,NL"]Coupon is not valid for your user role.[/alg_wc_cbur_translate]
lang="DE": the wrapped text shows only when the active language is DE.not_lang="DE,NL": the wrapped text shows for every language except DE and NL.
Attributes reference #
| Attribute | Purpose |
|---|---|
lang |
Language code(s) this text is for. Comma separate for several. |
not_lang |
Show for every language except the listed one(s). |
lang_text |
Inline form only: text shown when lang matches. |
not_lang_text |
Inline form only: fallback text for other languages. |
Combine with message placeholders #
The message field also supports %coupon_code% and %coupon_amount%, so you can mix placeholders and translation in one message. See customizing the “Coupon is not valid” message.
Need a hand? #
Our team answers every ticket on the Coupon by User Role support forum.
