Subscribe by Email custom fields

I am discovering the Subscribe by email plugin. Added NAME as a custom field, shows nicely on the pop-up window. All great.
How do I include this NAME field in the emails that are sent out?

  • Ash
    • WordPress Hacker

    Hello mpress

    Please copy all four files from /wp-content/plugins/subscribe-by-email/inc/mail-templates/views/ to /wp-content/themes/THEME_NAME/subscribe-by-email/ folder. You may need to create subscribe-by-email folder inside your theme folder. Here it's better to use child theme so that it doesn't get lost on theme update. Here is how you can create a child theme: https://premium.wpmudev.org/blog/how-to-create-wordpress-child-theme/

    Now, in any of those four copied files, the place where you want to show name, use the following:

    %SBE_NAME%

    And then, try the following code:

    add_filter( 'wp_mail', function( $atts ) {
    	global $wpdb;
    
    	$myposts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} WHERE post_title LIKE '%". $atts['to'] ."%'" ) ;
    	$subscriber = incsub_sbe_get_subscriber( $myposts[0]->ID );
    	if( ! isset( $subscriber ) ) return $atts;
    
    	$meta_value = $subscriber->get_meta( 'name', '' );
    
    	$data = '';
    	if( isset( $meta_value ) && $meta_value != '' ) $data = $meta_value;
    
    	$atts['message'] = str_replace( '%SBE_NAME%', $data, $atts['message'] );
    
    	return $atts;
    } );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.