• Resolved Colin

    (@colinsafranek)


    Hi, I’ve got the following snippet in my theme’s functions:

    /**
     * Add or remove users to MailChimp "groups" based on WP Role or WC Memberships and Membership Status
     */
    add_filter( 'mailchimp_sync_subscriber_data', function( $subscriber, $user )
    {
        // toggle interest ID based on user role
        if( in_array( 'wuwo_coach', $user->roles ) )
        {
            $subscriber->interests[ "c3a673d82e" ] = true; // add user to Membership Status -> Coach group
        }
        else
        {
        	$subscriber->interests[ "c3a673d82e" ] = false; // otherwise make sure they are not inhte Coach group
        }
    
        // Use WC Memberships functions to determine active "Member" or "Paused" status:
        if(
        	// If they are an ACTIVE member of Gyms or Kids/Teens:
        	   wc_memberships_is_user_active_member( $user->ID, 'session-plan' )
        	|| wc_memberships_is_user_active_member( $user->ID, 'kids-session-plan' )
        )
        {
            $subscriber->interests[ "42c6a43487" ] = true; // add user to "Member" group
            $subscriber->interests[ "7b642e4674" ] = false; // make sure they are removed from the "Paused" interest group
        }
        else if(
        	// If they are an INACTIVE member of Gyms or Kids/Teens:
        	   wc_memberships_is_user_member( $user->ID, 'session-plan' )
        	|| wc_memberships_is_user_member( $user->ID, 'kids-session-plan' )
        )
        {
        	$subscriber->interests[ "42c6a43487" ] = false; // remove user from "Member" interest group
            $subscriber->interests[ "7b642e4674" ] = true; // add user to "Paused" interest group
        }
    
        //////////////////////////////////////////////////////////////////////////////
        // add user to the "Products" Groupings based on membership product purchases:
        //////////////////////////////////////////////////////////////////////////////
    
        // Paying Customer?? Use WC Subscriptions function to determine if this user is paying for their subscription/s:
        if( wcs_user_has_subscription( $user->ID, '', 'active' ) )
        {
        	$subscriber->interests[ "79e1ec6496" ] = true; // add user to "Paying Customer" grouping
        }
        else
        {
        	$subscriber->interests[ "79e1ec6496" ] = false; // make sure they are NOT in the "Paying Customer" grouping
        }
    
        // Free Members: any memberships with status 'complimentary'
        $complimentary_args = array(
    	    'status' => array( 'complimentary' ),
    	);
    	$complimentary_memberships = wc_memberships_get_user_memberships( $user->ID, $complimentary_args );
    
        if( ! empty( $complimentary_memberships ) )
        {
        	$subscriber->interests[ "97fc802ada" ] = true; // add user to "Free Member" grouping
        }
    
        // Finishers digital product and 'finishers' membership):
        if( wc_memberships_is_user_member( $user->ID, 'finishers' ) )
        {
        	$subscriber->interests[ "89b80243f9" ] = true; // add user to "Finishers" grouping
        }
    
        // Gyms:
        if( wc_memberships_is_user_member( $user->ID, 'session-plan' ) )
        {
        	$subscriber->interests[ "efebc92735" ] = true; // add user to "Gyms" grouping
        }
    
        // Competitors:
        if( wc_memberships_is_user_member( $user->ID, 'comp-session-plan' ) )
        {
        	$subscriber->interests[ "70ee678397" ] = true; // add user to "Competitors" grouping
        }
    
        // Kids and Teens:
        if(
        	wc_memberships_is_user_member( $user->ID, 'kids-session-plan' )
        	|| wc_memberships_is_user_member( $user->ID, 'teens-session-plan' )
        )
        {
        	$subscriber->interests[ "089ab9402d" ] = true; // add user to "Kids and Teens" grouping
        }
    
    	return $subscriber;
    
    }, 10, 2 );

    All but one of the interest groupings seem to be functioning properly. The one that is not working is the first one, based on $user->roles. “wuwo_coach” is a custom role created by a plugin. I have over 100 users with that role. User Sync is successfully syncing them to my MailChimp list, but they are not being placed in the above interest group. I have triple checked that the interest grouping ID is correct, and I have run a manual sync 3 times, with no success. The “wuwo_coach” users are being added to the list, but are not being added to the grouping. I can’t figure out what is going wrong. The debug log does not go into detail, it only reports whether the user was successfully synced.

    How can I debug this filter? Can you see anything wrong with the code which would prevent it from working as expected?

    Thank you in advance for your assistance.

    Cheers!

    – Colin

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Colin

    (@colinsafranek)

    Is there a reason no one has answered this question?

    Looks like support is active. Why no love?

    Plugin Contributor Lap

    (@lapzor)

    Hi Colin,

    I see you created an issue at GitHub. Thank you!
    Our programmer is looking into this issue.

    https://github.com/ibericode/mailchimp-user-sync/issues/91

    UserSync issues have a slightly lower priority for us compared to MailChimp for WordPress and Boxzilla, but we will definitely get around to it.

    • This reply was modified 7 years, 9 months ago by Lap.
    • This reply was modified 7 years, 9 months ago by Lap.
    Thread Starter Colin

    (@colinsafranek)

    Ok, thanks Lap.

    Should I expect a response on this thread, or on GitHub?

    Thread Starter Colin

    (@colinsafranek)

    Nothing here, nothing on GitHub. Is anyone still looking into this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘User Sync, add to grouping based on user role not working.’ is closed to new replies.