How do I alter the success message when a user subscribes to a list

Article Last Updated: May 16, 2016

When a user successfully subscribes to a list, they are presented with the success message you have specified in the form settings (or the default message if you don’t have one setup). At times, you may need to conditionally display a success message – or maybe you want to use one of the user submitted values in the success message. In version 6.0.4.3 we’ve now included a new filter, allowing you to do just that.

`yikes-mailchimp-success-response`

Parameters:

  • $response_text – The success message text.
  • $form_id – The form ID that was submitted.
  • $merge_vars – The user submitted merge variables.
  • Example:

    The following example alters the success message for the form with ID 1. The snippet below also grabs the user submitted data for the form field ‘FNAME’, and uses that in the success response. For Example: If the user entered the name ‘John’ in the ‘FNAME’ field, the success response would then be “Thanks for subscribing John, please check your inbox.”.

    /**
    *	Filter the success response and use the 'FNAME' field
    *	@resource: https://github.com/yikesinc/yikes-inc-easy-mailchimp-extender/issues/455
    */
    function yikes_mailchimp_filter_success_text( $response_text, $form_id, $merge_vars ) {
    	if( $form_id == 1 ) {
    		$response_text = 'Thanks for subscribing ' . $merge_vars['FNAME'] . ', please check your inbox.';
    	}
    	return $response_text;
    }
    add_filter( 'yikes-mailchimp-success-response', 'yikes_mailchimp_filter_success_text', 10, 3 );
    

    Keep in mind that the $merge_vars variable contains all of the user submitted data, so if you have other fields you’d like to use – you can do so by specifying the merge tag. (eg: $merge_vars[‘LNAME’], $merge_vars[‘EMAIL’] etc.)