Support » Plugin: Mailchimp for WordPress » Only taking email to the list on Register

  • Resolved freixa21

    (@freixa21)


    Hey there!

    I followed this guide to make people opt to subscribe to my mailchimp list when they register to my website: https://kb.mc4wp.com/add-list-choice-registration-form/#

    I used the code of the guide and then in the plugin I went to Mailchimp for WP > Integrations > Registration Form > and activate it.

    Now Mailchimp is taking the email but not the First Name or Phone.

    I’m using the same list for a contact form 7 and is working good. I think I may have to declare the Merge tags somewhere? I don’t know…

    Any idea?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Tried this code from this guide.

    add_filter( 'mc4wp_integration_woocommerce_data', function( $data ) { 
    	
    	// Grab MailChimp field values from the current request
    	$data['First Name'] = sanitize_text_field( $_POST['billing_first_name'] ); 	
    	$data['Phone Number'] = sanitize_text_field( $_POST['billing_phone'] ); 
    
    	// Return the fields so the plugin knows to send them to MailChimp
    	return $data; 
    });

    Also tried with MERGE1, MERGE4 instead of First Name or Phone Number but still not working…

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    The code you used is for transferring data from WooCommerce.

    Can you please confirm if you are using the registration form for sending the user data to MailChimp.com? If yes, can you please share a link where I can test the registration form?

    Hi,

    Thank you so much for the answer, I really appreciate it. I’m using the default WooCommerce registration form and I added the Mailchimp checkbox and added that code but is only taking the email.

    The link of my website: bentosushi.es

    Thanks.

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    Can you please try the code at https://github.com/ibericode/mc4wp-snippets/blob/master/integrations/wp-registration-form/custom-registration-fields.php from line 23 onwards? Please make sure to modify the code to match your field names for name and number.

    Where I can find this field nomes? I changed for example:

    ‘TELEPHONE’ > ‘billing_phone’

    But still not taking it. I’m not very sure what to do, sorry for the ignorance.

    Thanks

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    The first field would be the name of the field in your MailChimp list. The 2nd is the field name in WooCommerce. I would recommend searching online for the various field names used by WooCommerce.

    freixa21

    (@freixa21)

    Hi

    I’m going to give you all the information so maybe you can help me better!

    Here the code you told me to add. I changed the fields for ‘billing_first_name’ and ‘billing_phone’ but I couldn’t make it work…

    /**
     * Register the custom fields with MailChimp for WordPress.
     */
    add_filter( 'mc4wp_integration_data', function( $data ) {
    	$field_names = array(
    		'billing_first_name',
    		'billing_phone'
    	);
    	foreach( $field_names as $field_name ) {
    		if( ! empty( $_POST[ $field_name ] ) ) {
    			$data[ $field_name ] = sanitize_text_field( $_POST[ $field_name ] );
    		}
    	}
    	return $data;
    });

    Here the code for add the fields to the register form and ADD it to the woocommerce database:

    function wooc_extra_register_fields() {?>
           <p class="form-row form-row-first">
           <label for="reg_billing_first_name"></label>
           <input type="text" class="input-text" name="billing_first_name" placeholder="Nombre" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
           </p>
           <p class="form-row form-row-last">
           <label for="reg_billing_last_name"></label>
           <input type="text" class="input-text" name="billing_last_name" placeholder="Apellidos" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
           </p>
           <p class="form-row form-row-wide">
           <label for="reg_billing_phone"></label>
           <input type="text" class="input-text" name="billing_phone" placeholder="Teléfono" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />
           </p>
           <div class="clear"></div>
           <?php
     }
     add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
    /**
    * VALIDAR DADES REGISTRE
    */
    
    function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
    
          if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
    
                 $validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
    
          }
    
          if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
    
                 $validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
    
          }
             return $validation_errors;
    }
    
    add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
    
        /**
        * Escriure dades a la BBDD.
        */
        function wooc_save_extra_register_fields( $customer_id ) {
            if ( isset( $_POST['billing_phone'] ) ) {
                         // Phone input filed which is used in WooCommerce
                         update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
                  }
              if ( isset( $_POST['billing_first_name'] ) ) {
                     //First name field which is by default
                     update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
                     // First name field which is used in WooCommerce
                     update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
              }
              if ( isset( $_POST['billing_last_name'] ) ) {
                     // Last name field which is by default
                     update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
                     // Last name field which is used in WooCommerce
                     update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
              }
        }
        add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

    Here the checkbox to subscribe the people to my mailchimp list.

    function myprefix_show_list_choice_in_registration() {
    	?>
    	<p>
        	<label>
            		<input name="_mc4wp_lists[]" type="checkbox" value="89d93e9a95"> <a class="registremch">Deseo mantenerme informado sobre las Ășltimas novedades, ofertas y promociones de Bento Sushi.</a>
        	</label>
    		</p>
    	<?php
    }
    
    add_action( 'register_form', 'myprefix_show_list_choice_in_registration' );

    Thanks for you help again Harish!

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    Thanks for sharing it, however, to debug this further, I’ll need to test your website. Please share with us a link to the registration page. You can also reach out to us at “support@mc4wp.com”.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.