add_filter( 'wpml_mailchimp_should_set_subscriber_language', callable $function_to_add, 10, 2 );
Description
This filter decides whether MailChimp Multilingual sends a language to Mailchimp as the subscriber language. Mailchimp stores it in the language field of the contact and uses it for its own emails, for example the double opt-in confirmation.
MailChimp Multilingual runs the filter for each sign-up that does not already have a language:
- A form sign-up. The language is the language of the form. When the Send the site language as the subscriber language, for forms and integrations setting is on, it is the site language. The
$form_idargument is the ID of the submitted form. - An integration sign-up, for example from the comment form, the registration form or the WooCommerce checkout. MailChimp Multilingual runs the filter only when the Send the site language as the subscriber language, for forms and integrations setting is on. The
$form_idargument is0.
The setting is in the Subscriber language row at Mailchimp for WPWPML. A sign-up that already has an MC_LANGUAGE field, in the form or in the data of the integration, already has a language. MailChimp Multilingual does not run the filter for it.
Return false to send no language for the sign-up. To send no language for any sign-up, use add_filter( 'wpml_mailchimp_should_set_subscriber_language', '__return_false' );.
On a translated page, the visitor submits the translated form, which has its own ID. To match one form in every language, get the ID of the original form with the wpml_object_id filter, as in the example below.
Arguments
Callback Function Parameters
The callback function accepts two parameters:
$enabledboolReturntrueto send the subscriber language, orfalseto send no language. Default:true.$form_idintThe ID of the MC4WP form that the visitor submitted. On a translated page, it is the ID of the translated form. It is0for an integration, for example the comment form or the WooCommerce checkout.
Example Usage
// Send no subscriber language for form 123 (in the default language) and its translations. add_filter( 'wpml_mailchimp_should_set_subscriber_language', function( $enabled, $form_id ) { $default_language = apply_filters( 'wpml_default_language', null ); $original_form_id = apply_filters( 'wpml_object_id', $form_id, 'mc4wp-form', true, $default_language ); return 123 === (int) $original_form_id ? false : $enabled; }, 10, 2 );