• Resolved liammitchell

    (@liammitchell)


    Hi,

    I added a filter in a plugin to add tags based on selected checkboxes.
    I noticed that the mailchimp api for PUT and PATCH does not actually update the Tags.

    I did figure a work-around but it is not great…

    Would much prefer it if mailchimp-for-wp could update tags for an existing subscription.

    Or maybe if an action could be made passing in the api, list_id, subscriber, existing_member_data after the submission?

    Also I can’t really remove tags for my use case as the same list is used across multiple forms/sites so it would be great to have an option configurable on the form to retain the current tags or to replace completely when updating.

    I sent a support request to Mailchimp about this, seems odd that updating a member list would not update the tags yet it can create the tags initially just fine.

    
    // Adding tags to Mailchimp subscribers.
    // This feature requires Mailchimp for WordPress version 4.4 or higher
    function mc4wp_extras_form_subscriber_data($subscriber) {
    	// Get post args _mc4wp_tags[] and set onto $subscriber->tags
    	if (isset($_POST['_mc4wp_tags'])) {
    		$additionalTags = array_filter($_POST['_mc4wp_tags'], 'strlen');
    		foreach ($additionalTags as $tag) {
    			$subscriber->tags[] = $tag;
    		}
    	}
    
    	// Note: This work-around is placed below as at the time of writing the MailChimp Patch API did not update Tags on existing member list records.
    
    	// Get the MailChimp API wrapper.
    	$api = mc4wp('api');
    
    	// Get the form ID.
    	$form_id = $_POST['_mc4wp_form_id'];
    
    	// Get the form.
    	/** @var MC4WP_Form $form */
    	$form = mc4wp_get_form( $form_id );
    
    	// Get information on the lists that are selected for the form.
    	$lists = $form->get_lists();
    
    	$email_address = $subscriber->email_address;
    
    	// Note: This feature is intended to be used with only 1 list selected
    	//        should multiple lists be selected for a form it will send multiple
    	//        redundant API requests.
    
    	$existing_member_data = null;
    	// loop through lists
    	foreach ($lists as $list_id) {
    		try {
    			// Get existing Member Data.
    			$existing_member_data = $api->get_list_member( $list_id, $email_address );
    		} catch(MC4WP_API_Resource_Not_Found_Exception $e) {
    		  // Member does not exist on list continue anyway as this is not a concern the tags will be added
    		  // when the MC4WP plugin adds the email to the list.
    		  continue;
    		} catch ( MC4WP_API_Exception $e ) {
    		  // Don't care?		  
    		  continue;
    		}
    
    		$existing_tags = [];
    		foreach ($existing_member_data->tags as $tag) {
    			$existing_tags[] = $tag->name;
    		}
    
        	// Merge the tags we are adding into any existing tags and ensure there are no duplicates.
        	$subscriber->tags = array_unique(array_merge($subscriber->tags, $existing_tags), SORT_REGULAR);
    
    		try {
    			// Build tags object to send to API.
    			$tags = [];
    			foreach ($subscriber->tags as $tag) {
    				$tags[] = [
    					'name' => $tag,
    					'status' => 'active'
    				];
    			}
    
        		// Update the list member tags.
        		// $subscriber->tags
        		$api->update_list_member_tags( $list_id, $email_address, [ 'tags' => $tags ] );
    		} catch(MC4WP_API_Resource_Not_Found_Exception $e) {
    		  // Don't care.
    		} catch ( MC4WP_API_Exception $e ) {
    		  // Don't care?
    		  //die($e->getMessage());
    		}
    	}
    
    	return $subscriber;
    }
    add_filter("mc4wp_form_subscriber_data", "mc4wp_extras_form_subscriber_data");
    
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello,

    Thanks for reaching out to us.

    Please note that it’s not possible yet to update tags for existing subscribers due to the way the API is setup. I would recommend using interest groups instead of tags as you can add/remove them easily.

    It does look like it is possible now. https://mailchimp.com/developer/guides/how-to-use-tags/

    Deleted

    • This reply was modified 4 years, 9 months ago by mkemichael.

    ANy update on this? All my audience list is SUBSCRIBED but every time I sell a new product to them I want to add a tag for that product. did they update the API yet?
    thanks!

    Plugin Contributor Lap

    (@lapzor)

    With the Premium add-on all your WooCommerce products and orders will be synced to MailChimp and you can create product follow up campaigns and segments based on ecommerce data such as what product or product category was bought how much money was spent etc. Using tags for this won’t work with our plugin.

    Hope that helps. If you have any questions, please let me know!

    Any news about this feature? Any work around at the moment? I need to update tags to users subcribers.
    Thanks

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey @anreig,

    This is still not possible and I would recommend using either product category or interest groups.

    This seems to be working now?

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey @markgrenville,

    Tags are now supported in our plugin.

    So How can I update tags for my existing subscribers? What filter or function should I use for WordPress? now I use function filter_mc4wp_form_subscriber_data( $subscriber ) .
    So when I unsubscribed one of my email addresses and archived and then re-signed up, I didn’t get the new tag that I added…

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hey @webwork1985,

    Have you enabled the “Update Existing Subscribers” option in the form?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Does not update tags on member list.’ is closed to new replies.