• Resolved taastrategies

    (@taastrategies)


    I constructed the code below based on the KB article and included it in functions.php of template child theme. The code shows up in the WP Theme child functions.php editor so it is being read into the theme.

    <?php
    /**
    * Generate child theme functions and definitions
    *
    * @package Generate
    */
    
    /*
    MailChimp for WordPress
    Send more WooCommerce subscription fields to MailChimp list
    https://mc4wp.com/kb/send-more-woocommerce-fields-to-list/
    Earl Adamy 02/18/2017
    */
    add_filter( ‘mc4wp_integration_woocommerce_data’, function( $data ) {
    
    // Grab MailChimp field values from the current request
    $data[‘PHONE’] = sanitize_text_field( $_POST[‘billing_phone’] );
    $data[‘ADDRESS1’] = sanitize_text_field( $_POST[‘billing_address_1’] );
    $data[‘ADDRESS2’] = sanitize_text_field( $_POST[‘billing_address_2’] );
    $data[‘CITY’] = sanitize_text_field( $_POST[‘billing_city’] );
    $data[‘STATE’] = sanitize_text_field( $_POST[‘billing_state’] );
    $data[‘ZIP’] = sanitize_text_field( $_POST[‘billing_postcode’] );
    $data[‘COUNTRY’] = sanitize_text_field( $_POST[‘billing_country’] );
    
    // Return the fields so the plugin knows to send them to MailChimp
    return $data;
    });

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    I set the MC4WP logging to Everything and then completed a checkout. The new subscriber was added to the MC list; however none of the extra fields were posted. The debug log shows:

    [2017-02-19 11:29:16] INFO: WooCommerce Checkout > Successfully subscribed xxx

    • This topic was modified 7 years, 9 months ago by taastrategies.
    • This topic was modified 7 years, 9 months ago by bdbrown.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Are the field names the correct internal MailChimp field names? You can find those under “Settings” > “List fields and *|MERGE|* tags” in your MC account. For me they are things like “MMERGE3”, “MMERGE4”, etc. — not the frontend labels.

    Thread Starter taastrategies

    (@taastrategies)

    They are the exact names shown in MailChimp’s field name settings for the list. There are two choices shown for each field, a user-name and a MERGE tag. The list indicates they can be used interchangeably.

    The MC4WP KB article on passing additional fields uses the user-name rather than the merge tag in the examples:

    https://mc4wp.com/kb/send-more-woocommerce-fields-to-list/

    By default the MailChimp for WordPress plugin sends over only the NAME, FNAME, LNAME and EMAIL fields. If you would like to add some more, a little editing is required.

    add_filter( 'mc4wp_integration_woocommerce_data', function( $data ) { 
    	
    	// Grab MailChimp field values from the current request
    	$data['COUNTRY'] = sanitize_text_field( $_POST['billing_country'] ); 	
    	$data['CITY'] = sanitize_text_field( $_POST['billing_city'] ); 
    
    	// Return the fields so the plugin knows to send them to MailChimp
    	return $data; 
    });

    I find it amazing that the MC4WP developers would like me to upgrade to their Premium plug-in when they can’t be bothered with answering basic questions.

    Plugin Contributor Lap

    (@lapzor)

    Hi,

    Thank you for your kind patience. We indeed give first priority to our Premium clients. Thank you for understanding.

    The code looks fine to me. I know that MailChimp.com can be pretty strict with validation on address fields. Personally I prefer using normal text fields instead.

    I suggest debugging this step by step, creating a new normal text field, and sending data to your field like this first:

    $data[‘NEWTEXTFIELD’] = ‘Test string 123’;

    If that works, try it again this time sending in some WooCommerce data:
    $data[‘NEWTEXTFIELD’] = sanitize_text_field( $_POST[‘billing_country’] );

    Also don’t forget to check for errors on the Other page of the MailChimp for WP plugin settings.

    Let us know the results of your test.

    Thank you!

    Thread Starter taastrategies

    (@taastrategies)

    I avoided using any specialized fields when I created the additional fields. The fields were all specified as “text” see screenshot:

    https://taastrategies.com/wp-content/uploads/2017/02/TAAS-MailChimp-List-Fields.png

    Never-the-less, I added TESTFIELD (NEWTEXTFIELD was too long) and replaced the code in functions.php with code as requested below:

    <?php
    /**
     * Generate child theme functions and definitions
     *
     * @package Generate
    */
    
    /*
    	MailChimp for WordPress
    	Send more WooCommerce subscription fields to MailChimp list
    	https://mc4wp.com/kb/send-more-woocommerce-fields-to-list/
    	Earl Adamy 02/18/2017
    */
    add_filter( 'mc4wp_integration_woocommerce_data', function( $data ) {
    	
    	// Grab MailChimp field values from the current request
    	$data[‘TESTFIELD’] = ‘Test string 123’;
    
    	// Return the fields so the plugin knows to send them to MailChimp
    	return $data;
    });

    There is absolutely nothing arriving except email, LNAME, and FNAME which, of course, are being sent from other code.

    • This reply was modified 7 years, 9 months ago by taastrategies.
    Plugin Contributor Lap

    (@lapzor)

    Hi,

    So it seems this code in your functions.php is not executed at all. Is there any other code there that makes you sure that child functions.php is loaded into your WordPress?

    Thread Starter taastrategies

    (@taastrategies)

    I would agree that it appears not to be executing. I know that functions.php is being loaded because Appearance >Customize >Editor shows it in the Templates list as “functions.php (generatepress_child/functions.php)”. In fact, I used the editor to substitute the test code.

    Hi, I was also trying to use this referenced code snippet.

    https://mc4wp.com/kb/send-more-woocommerce-fields-to-list/

    After digging into the plugin files, it seems the filter ‘mc4wp_integration_woocommerce_data’ doesn’t even exists. Was this an old filter that was removed from the plugin? Viewing the class-woocommerce.php file in the plugin, I don’t see any way to support adding extra fields from WooCommerce checkout.

    Can this filter get added back to the plugin?

    Thread Starter taastrategies

    (@taastrategies)

    Thank you, Tony, for doing the code digging to bring this topic back to life! WooCommerce is a supported integration by MailChimp and it’s hard to believe this capability is not already in the WooCommerce software. My first approach to the problem was via MailChimp and they said they’d take a look at the request which sounded like it would happen .. never. I’m still waiting for a resolution here.

    Plugin Contributor Lap

    (@lapzor)

    Hi,

    The mc4wp_integration_woocommerce_data should still work/still exists in our code.
    Are you still experiencing this problem in the latest version of our plugin?

    Plugin Contributor Lap

    (@lapzor)

    Since there have been no replies to this topic for awhile I will now close this ticket as resolved.
    If you still have a problem or you have a similar problem as posted above, please open a NEW topic. Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Manually send more WooCommerce fields not working’ is closed to new replies.