Skip to content

Editing Member Tags

khungate edited this page Jul 25, 2023 · 5 revisions

Welcome to the guide on Editing Member Tags in the MailChimp for WooCommerce Integration. This guide will help you understand how to modify the member tags array using the mailchimp_user_tags filter.

Overview

Functionality

By default, Mailchimp for WooCommerce adds any tag(s) configured on an Audience's settings page to the member/customer when they are being synced. However, if you want to add or remove tags, you can edit the tags array by adding code to your themes or plugins.

Code Examples

Adding and Removing Tags

Here's an example of how to add one tag and remove another:

function my_tags($tags, $email) {
    $new_tags = array(
        array(
            'name' => '<<tag-to-add>>',
            'status' => 'active'
        ),
        array(
            'name' => '<<tag-to-remove>>',
            'status' => 'inactive'
        ),
    );
    return array_merge($tags, $new_tags);
}
add_filter('mailchimp_user_tags', 'my_tags', 10, 2);

Removing an Existing Tag

Here's an example of how to remove a tag that was previously added to the user:

function my_tags($tags) {
    foreach ($tags as $tag) {
        if ($tag['name'] == '<<existing-tag-to-remove>>'){
            $tag['status'] = 'inactive';
        } 
    }
    return $tags;
}
add_filter('mailchimp_user_tags', 'my_tags', 10, 1);

Next Steps

After implementing these functions, you should monitor your member tags to ensure they are being updated correctly. If you encounter any issues, consider adding error handling to your functions to manage potential problems.