• Resolved sandeld

    (@sandeld)


    I’m currently trying to send a contact’s WooCommerce Membership Level to a field/mergetag in MailChimp. I feel like this should be relatively easy since the membership level information is available on the WordPress user dashboard:

    When trying to use the “Send Additional Fields” function within the Users Sync settings, no type of Woocommerce membership field tags get auto-populated.

    Which led me to this code:

    add_filter( 'mailchimp_sync_user_data', function( $data, $user ) {
        $data['WEBSITE'] = $user->user_url;
        return $data;
    }, 10, 2 );

    I have been able to map the fields correctly by replacing ‘WEBSITE’ with ‘LEVEL’ (as I have it setup in my MailChimp list), but when I replace user_url with woocommerce-membership (as it is stored on my website in WooCommerce), it send the number “0” instead of “White-Truth” as referenced in the first picture.

    I’m sure I’m close, and I’m sure it’s simple, but I can’t seem to figure out how to pull the membership level from WooCommerce into your plugin and then send it off to MailChimp.

    Any help would be greatly appreciated.

    • This topic was modified 6 years, 3 months ago by sandeld.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sandeld

    (@sandeld)

    Update:

    As you can tell, I’m a beginner php programmer, but I am starting to understand a little more. I’ve now changed the code to something like this, though it’s still not working:

    add_filter( 'mailchimp_sync_user_data', function( $data, $user ) {
    	$mem_level = wc_memberships_get_user_active_memberships( $user );
    	$data['LEVEL'] = $mem_level;
        return $data;

    I’ve even tried removing the intermediate step of $mem_level but that didn’t work either.

    Plugin Author Harish Chouhan

    (@hchouhan)

    Hello,

    From what you described, “woocommerce-membership” seems to be storing the level which is “0”. Can you please contact the developers of the “WooCommerce Membership” plugin and ask them which variable saves the label/name of a level?

    Thread Starter sandeld

    (@sandeld)

    Hello, I managed to figure it out, though as someone that has to teach himself, it definitely wasn’t easy.

    I’m sure this isn’t the most elegant PHP code in the world, but if anyone else needs this or wants to make suggestions on how to do it better, here is what I finally used.

    add_filter( 'mailchimp_sync_user_data', function( $data, $user ) 
    {
    	$user_id = $user->ID;
    	$plan_ids = array(539, 518, 511);
    	$arrlength = count($plan_ids);
    	for ($x = 0; $x < $arrlength; $x++)
    	{
    		$user_membership = wc_memberships_get_user_membership( $user_id, $plan_ids[$x] );
    		if (!empty($user_membership))
    		{
    			$active_level = $user_membership->plan->name;
    			$data['LEVEL'] = $active_level;
    		}
    	}
    	return $data; 
    }, 10, 2 );

    I also need to add an else in there somewhere in case a user doesn’t have a membership level, but I’ll get to that later.

    Plugin Contributor Lap

    (@lapzor)

    Glad you found a solution that works, thanks for sharing!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Syncing with WooCommerce Memberships’ is closed to new replies.