• baugh05

    (@baugh05)


    I keep getting email notifications for every order stating “Your merge fields were invalid.” I have tried the following function:

    // tie into the WooCommerce MailChimp 'ss_wc_mailchimp_subscribe_merge_vars' action filter to modify the MailChimp merge vars
    function ss_wc_modify_mailchimp_merge_fields( $merge_vars, $order_id ) {
        // By default $merge_vars will look like array( 'FNAME' => 'Joe', 'LNAME' => 'Smith', 'EMAIL' => '[email protected]' );
    
        // Retrieve the WooCommerce order
        $order = new WC_Order( $order_id );
      
      	// Get the order billing address
        $billing_address = $order->get_address( 'billing' );
    
        // Get the billing address state
        $state = $billing_address[ 'state' ];
      
      	// Get the billing address country
        $country = $billing_address[ 'country' ];
    
        // let's add a new 'STATE' merge field - NOTE: You'll need to change this to the actual name
        // of your merge field in MailChimp
        $merge_vars[ 'STATE' ] = $state;
    	$merge_vars[ 'COUNTRY' ] = $country;
      
        return $merge_vars;
    }
    add_filter( 'ss_wc_mailchimp_subscribe_merge_vars' , 'ss_wc_modify_mailchimp_merge_fields', 10 , 2 );

    I need State and Country fields to save to mail chimp as they are required by my signup form. Any help is greatly appreciated. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Adam Anderly

    (@anderly)

    The filter ss_wc_mailchimp_subscribe_merge_vars has been changed to ss_wc_mailchimp_subscribe_merge_tags in version 2.0. See this help article for updated action filter example: https://support.saintsystems.com/hc/en-us/articles/208477286-Sending-additional-fields-to-MailChimp

    Thread Starter baugh05

    (@baugh05)

    Thanks for the reply Adam! I am still receiving the error email using the following code:

    // tie into the WooCommerce MailChimp 'ss_wc_mailchimp_subscribe_merge_vars' action filter to modify the MailChimp merge vars
    function ss_wc_modify_mailchimp_merge_fields( $merge_vars, $order_id ) {
        // By default $merge_tags will look like array( 'FNAME' => 'Joe', 'LNAME' => 'Smith', 'EMAIL' => '[email protected]' );
    
        // Retrieve the WooCommerce order
        $order = new WC_Order( $order_id );
      
      	// Get the order billing address
        $billing_address = $order->get_address( 'billing' );
    
        // Get the billing address state
        $state = $billing_address[ 'state' ];
      
      	// Get the billing address country
        $country = $billing_address[ 'country' ];
    
        // let's add a new 'STATE' merge field - NOTE: You'll need to change this to the actual name
        // of your merge field in MailChimp
        $merge_tags[ 'STATE' ] = $state;
    	$merge_tags[ 'COUNTRY' ] = $country;
      
        return $merge_tags;
    }
    add_filter( 'ss_wc_mailchimp_subscribe_merge_tags' , 'ss_wc_modify_mailchimp_merge_fields', 10 , 2 );

    Any suggestions on how I can fix the snippet to get billing address state and country fields to save to mail chimp?

    Plugin Author Adam Anderly

    (@anderly)

    Can you double-check the required merge tags you have setup in MailChimp and the exact names. It looks like it doesn’t like the merge tags that you’re sending it which means there is a mismatch.

    The plugin defaults to sending FNAME, LNAME and EMAIL so make sure those are setup and not named differently. Then, make sure you have STATE and COUNTRY setup and as long as they all match, it should go through.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Your merge fields were invalid.’ is closed to new replies.