Skip to content

Meta Key Validation Filter During Sync Process

khungate edited this page Aug 29, 2023 · 2 revisions

This tutorial aims to walk you through the process of utilizing filters to validate meta keys when updating product data. The guide will offer insights into how you can selectively omit certain keys from being added to the Mailchimp sync queue.

Why Validate Meta Keys?

Starting from version v3.2, the Mailchimp WooCommerce plugin allows for more granular control over the data that gets synced. This guide elaborates on how to use the mailchimp_valid_keys filter function to achieve this.

Prerequisites

Before diving into the code, ensure you have the following:

  • The latest version Mailchimp WooCommerce plugin installed and activated
  • Basic understanding of WordPress hooks and filters

Code Snippets

Disabling Sync for Specific Product Price Updates

Here's a code snippet that demonstrates how to prevent syncing when a product's regular price is updated:

function mailchimp_valid_keys( $valid_keys ) {
    if ( ( $key = array_search('regular_price', $valid_keys) ) !== false ) {
        unset($valid_keys[$key]);
    }
    return $valid_keys;
}
add_filter( 'mailchimp_filter_valid_keys', 'mailchimp_valid_keys' );