• Resolved u3r

    (@u3r)


    Hi. I’m trying to add “City” to WooCommerce data to send over to MailChimp during every order. I’ve added this code to functions.php:

    function custom_mailchimp_sync_user_mergetags($user, $merge_tags){
    $billing_country = get_user_meta($user->ID, ‘billing_country’, true);
    if( !empty($billing_country) ){
    $merge_tags[‘CITY’] = $billing_country;
    }
    return $merge_tags;
    }
    add_filter( ‘mailchimp_sync_user_mergetags’, ‘custom_mailchimp_sync_user_mergetags’, 100, 2);

    (Which I took from here: https://github.com/mailchimp/mc-woocommerce/wiki/Custom-Merge-Tags )

    Anyways, I’ve added custom merge tag in mailchimp as well: https://prnt.sc/20x82r7

    But data just won’t appear in mailchimp. What have I missed? Thanks.

Viewing 1 replies (of 1 total)
  • I just did this myself. The issue if you need to use the ‘Address’ merge tag. Then within that the address tags need to be in an array. Below is my code the syncs over billing address and phone.

    NOTE: For phone number to display right in MailChimp I found you need to format the telephone before sending it over.

    function custom_format_telephone($phone_number)
    {
    //Remove all formatting
    $cleaned = preg_replace(‘/[^[:digit:]]/’, ”, $phone_number);
    //seperate phone into its parts
    preg_match(‘/(\d{3})(\d{3})(\d{4})/’, $cleaned, $matches);
    //Send back phone number in xxx-xxx-xxxx format.
    return “{$matches[1]}-{$matches[2]}-{$matches[3]}”;
    }

    function custom_user_merge_tags($merge_vars, $user) {

    // Get the WooCommerce customer object
    $customer = new WC_Customer($user->ID);
    // Build Address Array
    $address = array();
    $address[“addr1”] = $customer->get_billing_address_1();
    $address[“addr2”] = $customer->get_billing_address_2();
    $address[“city”] = $customer->get_billing_city();
    $address[“state”] = $customer->get_billing_state();
    $address[“zip”] = $customer->get_billing_postcode();
    $address[“country”] = $customer->get_billing_country();

    //Assign to MailChimp merge tag name
    $merge_vars[‘ADDRESS’] = $address;
    $merge_vars[‘PHONE’] = custom_format_telephone((string) $customer->get_billing_phone());

    // return the merge tag array to be submitted.
    return $merge_vars;
    }

    add_filter(‘mailchimp_sync_user_mergetags’, ‘custom_user_merge_tags’, 100, 2);`

Viewing 1 replies (of 1 total)
  • The topic ‘Can’t get wordpress to send additional merge tags from woocommerce to mailchimp’ is closed to new replies.