Sometimes it’s needed to welcome your subscribers with friendlier words such as “Hello” or “Hi”. In some countries, it’s also common to have different salutations based on the user’s gender.

If you like to welcome your new subscribers with either “Welcome Mrs. Jackson” or “Welcome Mr. Johnson” you need to get the “Mrs.” or “Mr.” in a custom field.

Screenshot 2015-10-10 um 11.52.38

First, make sure you are having a custom field – preferably radio buttons – where you ask for the subscriber’s gender:

You also need one custom field for the actual salutation so set up a new one as text area:

Screenshot 2015-10-10 um 11.54.48

After you have applied the gender custom field to your form you need some code to add to your theme’s function.php.

Adjust the strings if needed.

function mailster_add_salutation( $entry ) {
if( isset( $entry['gender'] ) ){
if( $entry['gender'] == 'Female' ){
$entry['salutation'] = 'Mrs.';
}else if( $entry['gender'] == 'Male' ){
$entry['salutation'] = 'Mr.';
}
}
return $entry;
}
add_filter('mailster_verify_subscriber', 'mailster_add_salutation');

Mailster will run this snippet every time you add a new subscriber to your user base and if gender has been defined it will automatically add it’s the appropriate salutation.

Apply salutation to your existing users

If you like to apply this rule to your existing subscribers you have to run a bulk action.

Select your subscribers on the overview page and choose “Verify” from the Bulk Actions Drop Down menu.

Add salutation via custom dynamic tag

If you know how to add a custom dynamic tag you can also add one to your site.┬áThis makes it easy to change it in the future as you don’t have to store it in the database.

Add this snippet to your site:

mailster_add_tag( 'salutation', function( $option, $fallback, $campaignID = null, $subscriberID = null ) {
if ( $subscriber = mailster( 'subscribers' )->get( $subscriberID ) ) {
switch ( $subscriber->gender ) {
case 'Male':
return 'Dear Mr.';
case 'Female':
return 'Dear Mrs.';
default:
return 'Dear';
}
}
// return the fallback
return $fallback;
}, 10, 4 );

This way you don’t need the “salutation” custom field from above.