在短代码中,您总是需要返回一些内容。使代码具有很强的逻辑性和可读性也是一种很好的做法。以下是PHP逻辑运算符列表:http://php.net/manual/en/language.operators.logical.phpWordPress语言环境代码的完整列表:https://wpastra.com/docs/complete-list-wordpress-locale-codes/
以下是以英语作为备份/回退语言的示例:
function coupon_shortcode() {
$logged_in = is_user_logged_in();
if (get_locale() == \'fr_FR\' && $logged_in == false) {
return \'<div class="discount"><h3 style="text-align: left;">C’est votre première commande?</h3><p style="text-align: left;">Demandez votre code de réduction d’une valeur de 20 Euros.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://atremoplus.fr/bienvenue/">Recevoir mon code</a></span></p></div>\';
}
elseif (get_locale() == \'de_DE\' && $logged_in == false) {
return \'<div class="discount"><h3 style="text-align: left;">Ist dies Ihre erste Bestellung?</h3><p style="text-align: left;"> Fordern Sie Ihren persönlichen 20 Euros Rabatt.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://www.atremoplus.net/de/atremoplus-kaufen/">Gutscheincode anfordern</a></span></p></div>\';
}
elseif (get_locale() == \'es_ES\' && $logged_in == false) {
return \'<div class="discount"><h3 style="text-align: left;">¿Este es su primer pedido?</h3><p style="text-align: left;"> Solicite su código de descuento por un valor de 20 euros.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://www.atremoplus.net/es/comprar-atremoplus/">Recibir mi código</a></span></p></div>\';
}
elseif ($logged_in == false) { // Backup/fallback language is English and is shown only when user is not logged in
return \'<div class="discount"><h3 style="text-align: left;">Is this your first order?</h3><p style="text-align: left;">Request your discount code for a value of 20 euros.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://www.atremoplus.net/welcome-coupon/">Receive my code
</a></span></p></div>\';
}
}
add_shortcode(\'coupon\', \'coupon_shortcode\');
以下是西班牙语作为备份/回退语言的示例:
function coupon_shortcode() {
$logged_in = is_user_logged_in();
if (get_locale() == \'en_US\' && $logged_in == false) {
return \'<div class="discount"><h3 style="text-align: left;">Is this your first order?</h3><p style="text-align: left;">Request your discount code for a value of 20 euros.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://www.atremoplus.net/welcome-coupon/">Receive my code
</a></span></p></div>\';
}
elseif (get_locale() == \'fr_FR\' && $logged_in == false) {
return \'<div class="discount"><h3 style="text-align: left;">C’est votre première commande?</h3><p style="text-align: left;">Demandez votre code de réduction d’une valeur de 20 Euros.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://atremoplus.fr/bienvenue/">Recevoir mon code</a></span></p></div>\';
}
elseif (get_locale() == \'de_DE\' && $logged_in == false) {
return \'<div class="discount"><h3 style="text-align: left;">Ist dies Ihre erste Bestellung?</h3><p style="text-align: left;"> Fordern Sie Ihren persönlichen 20 Euros Rabatt.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://www.atremoplus.net/de/atremoplus-kaufen/">Gutscheincode anfordern</a></span></p></div>\';
}
elseif ($logged_in == false) { // Backup/fallback language is Spanish and is shown only when user is not logged in
return \'<div class="discount"><h3 style="text-align: left;">¿Este es su primer pedido?</h3><p style="text-align: left;"> Solicite su código de descuento por un valor de 20 euros.</p><p style="text-align: left;"><span style="text-decoration: underline;"><a class="myButton" href="https://www.atremoplus.net/es/comprar-atremoplus/">Recibir mi código</a></span></p></div>\';
}
}
add_shortcode(\'coupon\', \'coupon_shortcode\');