We recently inherited a WordPress project with a custom Mailchimp integration that wasn’t subscribing users properly. The issue wasn’t completely silent—Mailchimp was rejecting the request—but with no real logging in place, it wasn’t obvious what was going wrong.
After digging through the code and Mailchimp’s API docs, we found the culprit: merge_fields
. Specifically, the integration was passing an empty array when no merge fields were present, but Mailchimp expects merge_fields
to be an object, even if it's empty.
Here’s the fix:
// Fix: Mailchimp expects merge_fields to be an object, not an empty array
$merge_fields = empty($filtered_merge) ? (object)[] : $filtered_merge;
A small change, but it made all the difference. Once we cast the empty array to an empty object, subscriptions started working again.