Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Last active March 14, 2025 21:13
Show Gist options
  • Save goranefbl/0954780d53a78918406c631a1c5c0488 to your computer and use it in GitHub Desktop.
Save goranefbl/0954780d53a78918406c631a1c5c0488 to your computer and use it in GitHub Desktop.
coupon email translatable
<?php
/**
* Email Body
*
* @see https://wpgens.com/docs/how-to-edit-template-files-and-keep-them-after-plugin-update/
* @version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
function get_email_text($key, $language) {
$email_text = array(
'en_GB' => array(
'heading' => 'Your Special Discount Code',
'message' => 'Thank you for your interest! Here is your coupon code:',
'shop_now' => 'Shop Now',
'expires' => 'Expires: '
),
'nl_NL' => array(
'heading' => 'Jouw Speciale Kortingscode',
'message' => 'Bedankt voor je interesse! Hier is je kortingscode:',
'shop_now' => 'Shop Nu',
'expires' => 'Verloopt op: '
),
'fr_FR' => array(
'heading' => 'Votre Code de Réduction Spécial',
'message' => 'Merci pour votre intérêt ! Voici votre code promo :',
'shop_now' => 'Acheter Maintenant',
'expires' => 'Expire le : '
),
'de_DE' => array(
'heading' => 'Ihr Spezieller Rabattcode',
'message' => 'Vielen Dank für Ihr Interesse! Hier ist Ihr Gutscheincode:',
'shop_now' => 'Jetzt Einkaufen',
'expires' => 'Gültig bis: '
),
'it_IT' => array(
'heading' => 'Il Tuo Codice Sconto Speciale',
'message' => 'Grazie per il tuo interesse! Ecco il tuo codice coupon:',
'shop_now' => 'Acquista Ora',
'expires' => 'Scade il: '
),
'es_ES' => array(
'heading' => 'Tu Código de Descuento Especial',
'message' => '¡Gracias por tu interés! Aquí está tu código de cupón:',
'shop_now' => 'Comprar Ahora',
'expires' => 'Caduca el: '
)
);
if (isset($email_text[$language]) && isset($email_text[$language][$key])) {
return $email_text[$language][$key];
}
// Fallback to English if translation not found
return isset($email_text['en_GB'][$key]) ? $email_text['en_GB'][$key] : "Text not found for key: $key";
}
// Get current language using WordPress locale
$current_language = get_locale();
// For order-specific emails, you might want to use this function instead
function get_order_language($order_id) {
$trp_order_language = get_post_meta($order_id, 'trp_language', true);
return $trp_order_language ? $trp_order_language : get_locale();
}
// Uncomment and use this if it's an order-specific email
// if (isset($order_id)) {
// $current_language = get_order_language($order_id);
// }
// Use translated text instead of variables
$heading_text = get_email_text('heading', $current_language);
$message_text = get_email_text('message', $current_language);
$shop_now_text = get_email_text('shop_now', $current_language);
$expires_text = get_email_text('expires', $current_language);
?>
<tbody>
<?php if(!$use_woo_template) { ?>
<tr>
<td style="background-color:<?php echo $color;?>;font-size:1px;line-height:3px" class="topBorder" height="3">&nbsp;</td>
</tr>
<tr>
<td style="font-size:1px;line-height:1px" height="50">&nbsp;</td>
</tr>
<?php } ?>
<tr>
<td align="center" valign="top" style="padding-bottom:40px" class="imgHero"><a href="#" style="text-decoration:none" target="_blank"><img alt="<?php echo esc_attr($heading_text); ?>" border="0" src="<?php echo WPGENS_RAF_URL. 'assets/img/coupon.png'; ?>" style="width:100%;max-width:300px;height:auto;display:block" width="300"></a></td>
</tr>
<tr>
<td align="center" valign="top" style="padding-bottom:5px;padding-left:20px;padding-right:20px" class="title">
<h2 class="bigTitle" style="color:#313131;font-family:&#39;Open Sans&#39;,Helvetica,Arial,sans-serif;font-size:26px;font-weight:600;font-style:normal;letter-spacing:normal;line-height:34px;text-align:center;padding:0;margin:0"><?php echo $heading_text; ?></h2></td>
</tr>
<tr>
<td style="font-size:1px;line-height:1px" height="25">&nbsp;</td>
</tr>
<tr>
<td align="center" valign="top" style="padding-bottom:35px;padding-left:20px;padding-right:20px" class="subTitle">
<p style="font-family:'Open Sans',Helvetica,Arial,sans-serif;font-size:16px;font-weight:400;font-style:normal;letter-spacing:normal;line-height:24px;text-align:center;padding:0;margin:0;"><?php echo $message_text; ?></p></td>
</tr>
<tr>
<td align="center" valign="top" style="padding-bottom:5px;padding-left:20px;padding-right:20px" class="offerTitle">
<p class="bigTitle" style="color:<?php echo $color; ?>;font-family:'Open Sans',Helvetica,Arial,sans-serif;font-size:24px;font-weight:400;font-style:normal;letter-spacing:normal;line-height:36px;text-align:center;padding:0;font-weight: bold;margin:0;max-width: 300px;padding: 10px;border: 2px dashed #ddd;"><?php echo $coupon_code; ?></p>
</td>
</tr>
<tr>
<td style="font-size:1px;line-height:1px" height="30">&nbsp;</td>
</tr>
<tr>
<td align="center" valign="top" style="padding-bottom:5px;padding-left:20px;padding-right:20px" class="btnCard">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tbody>
<tr>
<td align="center" style="background-color:<?php echo $color;?>;padding-top:10px;padding-bottom:10px;padding-left: 50px;padding-right: 50px;border-radius:2px;" class="postButton"><a href="<?php echo get_home_url(); ?>" style="color:#fff;font-family:&#39;Open Sans&#39;,Helvetica,Arial,sans-serif;font-size: 16px;font-weight:600;letter-spacing:1px;text-transform:uppercase;text-decoration:none;" target="_blank"><?php echo $shop_now_text; ?></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
<?php if($expiry) { ?>
<tr>
<td align="center" valign="top" style="padding-bottom:40px;padding-left:20px;padding-right:20px" class="infoDate">
<p class="midText" style="color:#333;font-family:&#39;Open Sans&#39;,Helvetica,Arial,sans-serif;font-size:11px;font-weight:700;line-height:20px;text-align:center;padding:0;margin:0"><?php echo $expires_text . $expiry; ?></p>
</td>
</tr>
<?php } ?>
<tr>
<td style="font-size:1px;line-height:1px" height="10">&nbsp;</td>
</tr>
</tbody>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment