Skip to main content

benecaster_email_template_locale

Filter Free Since v1.0.0

Filters the locale used to resolve the email template file path. Fires per email send, after the default locale has been determined from WordPress settings. Use to send specific email types or subscriber segments in a different locale.

Parameters

Name Type Default Description
$locale string Locale code (e.g. 'en_US') used for template file resolution
$user_id int|null WordPress user ID of the recipient, or null for admin emails
$show_id int|null ID of the show, or null when not show-specific
$email_type string Email type string identifying which template is being resolved

Returns: string

Example

add_filter( 'benecaster_email_template_locale', function( $locale, $user_id, $show_id, $email_type ) {
    // Send welcome emails to Spanish speakers in es_ES.
    if ( 'welcome' === $email_type && $user_id ) {
        $lang = get_user_meta( $user_id, 'locale', true );
        if ( str_starts_with( $lang, 'es_' ) ) {
            return 'es_ES';
        }
    }
    return $locale;
}, 10, 4 );

Affects

  • Email template file resolution