• Resolved robgwen

    (@robgwen)


    Hello,
    I’am using your plugin (free version) on a wpml website.
    On the shortcode form ([mc4wp_form]) i can place the following code to let Mailchimp know which language the user is watching:
    <input type=”hidden” name=”MC_LANGUAGE” value=”{language}” />
    This works like a charm!
    Where can i place this piece of code in the Checkboxes ( on register and checkout pages), so mailchimp knows which language the user is using?

    Thx Rob

    https://wordpress.org/plugins/mailchimp-for-wp/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello Rob,

    To add additional fields to your Registration, Comment and other forms you would need to use filters.

    Please find 2 example code for adding that field to your WP Registration & Comment form:

    function myprefix_show_wpml_in_registration() {
    	?>
            <input type="hidden" name="MC_LANGUAGE" value="{language}" />
    	<?php
    }
    add_action( 'register_form', 'myprefix_show_wpml_in_registration' );

    Comment Form

    function myprefix_show_wpml_in_comment_form() {
        ?>
             <input type="hidden" name="MC_LANGUAGE" value="{language}" />
        <?php
    }
    add_action( 'comment_form', 'myprefix_show_wpml_in_comment_form' );

    I hope that helps.

    Thread Starter robgwen

    (@robgwen)

    Hello Harish,
    Thanks for your reply.
    I pasted the code in my theme’s function.php.
    The code <input type=”hidden” name=”MC_LANGUAGE” value=”{language}” /> is showing up on the register form but the: value=”{language}” stays unchanged and the language code “nl” is not loaded.
    In your mailchimp subscripe form which i have put on the same page the: value=”{language}” gets replaced by value=”{nl}” like it should be.
    Any sugestions?
    Thx Rob

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello Rob,

    I apologize for error in my previous code. Can you please replace the hidden input field with below:

    <input type="hidden" name="MC_LANGUAGE" value="<?php echo get_locale(); ?>" />

    Our language shortcode only works within our forms. But the above code should work through WordPress.

    Let me know if that works.

    Thread Starter robgwen

    (@robgwen)

    Hello Harish,

    Thank you!
    That code is working.
    How can i make it work on the woocommerce checkout form?

    Thx Rob

    Thread Starter robgwen

    (@robgwen)

    Hello Harish,

    It looks like the code is not working properly.
    The landcode gets filled in but it gives the dubble language code.
    value=”de_DE”.
    it needs te be value=”de”.
    Could that be fixed?

    Thx Rob

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello Rob,

    Can you please try this code instead <input type="hidden" name="MC_LANGUAGE" value="<?php echo substr( get_locale(), 0, 2 ); ?>" />. Let me know if it works.

    Regarding WooCommerce checkout, it would require creating the custom field first using WooCommerce filters. While I would not be able to provide you the code for the same, I’ll see if my colleagues can assist with it.

    Thread Starter robgwen

    (@robgwen)

    Hello Harish,

    the new code is working!
    Thank you!
    Would be great if one of your colleagues could assist me with the woocommerce checkout form.

    THX Rob

    Plugin Author Danny van Kooten

    (@dvankooten)

    Hi Rob,

    Sorry for the delay in following up on this one but if you want to send the locale to MailChimp, I’d use the following so it automatically works for everything.

    add_filter( 'mc4wp_merge_vars', function( $merge_vars ) {
    	$merge_vars['MC_LANGUAGE'] = substr( get_locale(), 0, 2 );
    	return $merge_vars;
    });

    This won’t show any additional fields in the forms but I think that’s actually good, as otherwise users would be able to edit the values that would be sent to MailChimp.

    Please note that by default, the browser language of your visitor is sent to MailChimp along with their IP Address. In most cases, this is enough for MailChimp to correctly guess the user’s language, it might even be better than sending your site language but I leave that up to you.

    Hope that helps. If not, let me know!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WPML language subscribing’ is closed to new replies.