• Anonymous User 7276204

    (@anonymized-7276204)


    Hi, I am using User Meta Pro (which creates custom meta data in the wp_usermeta table).

    I have a custom field called “newsletter” which is just a checkbox.

    I want to use the filter provided in the plugin docs to sync only those who have checked that they want to receive newsletters.

    I believe the easiest way to do this is just by saying to sync where $newsletter is not empty:

    add_filter( 'mailchimp_sync_should_sync_user', function( $subscribe, $user ) {
    
        // check for custom user field
        if( !empty( $newsletter ) ) {
            return true;
        }
    
        // do not subscribe otherwise
        return false;
    });

    However, this doesn’t seem to be working. In the “Status” pane in the backend I get 0/xxxx indicating to me that it does not find anyone matching those criteria.

    What am I doing wrong here?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Lap

    (@lapzor)

    Where are you loading the custom user field into the $newsletter variable?
    I think you should find it somewhere in $user. Maybe you can dump $user and take a look in there?

    Hope that helps,

    Thread Starter Anonymous User 7276204

    (@anonymized-7276204)

    Still not working, I played around with the code a bit using snippets from Github and currently have this:

    add_filter( 'mailchimp_sync_should_sync_user', function( $sync, $user ) {
    
        // create array of users 
    
        $subscribed = new WP_User_Query( array( 'meta_key' => 'newsletter' ) );
    	
        // check for custom user field
    
        if ( ! empty( $subscribed->results ) ) {
    	foreach ( $subscribed->results as $user ) {
            	return $sync;
    	}
        }
    
        // do not subscribe otherwise
        return false;
    });

    I’ve also tried with $subscribe instead of $sync but it’s not working.

    I dumped the contents of my array in a test, and it does return the users that have subscribed, so the plugin should be finding them… I’m not sure what I’m doing wrong exactly.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Sync using user meta’ is closed to new replies.