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

    (@hchouhan)

    Hello Florian,

    Can you please share a link of the code you had tried by reading on our website?

    The top bar currently has only 1 instance so you would need to use plugins like WPML, etc. to convert the text to any other languages of your choice.

    Thread Starter flo.ei

    (@floei)

    Hi Harish,
    I used this code: https://mc4wp.com/kb/set-lists-based-site-language/

    function myprefix_filter_mc4wp_lists( $lists ) {
    	$list_id_spanish_list = '123abcdef456';
    	$list_id_english_list = '456defabc123';
    
    	if( defined( 'ICL_LANGUAGE_CODE') ) {
    		switch( ICL_LANGUAGE_CODE ) {
    
    			// spanish
    			case 'es':
    				$lists = array( $list_id_spanish_list );
    			break;
    			// english
    			case 'en':
    				$lists = array( $list_id_english_list );
    			break;
    		}
    	}
    	return $lists;
    }
    add_filter( 'mc4wp_lists', 'myprefix_filter_mc4wp_lists' );

    The problem is not to translate it, I already use WPML and it works to translate the bar, but I want to sign the users up into different lists according the language.

    Thanks a lot
    Flo

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello Florian,

    The code above is for the same purpose, i.e. to subscribe a user to a different list based on their language. The only modification you would have to do is change the filter name from “myprefix_filter_mc4wp_lists” to “myprefix_filter_mctb_lists”.

    What I have changed is mc4wp to mctb. Please do test this and let me know if it works.

    Thread Starter flo.ei

    (@floei)

    Hi Harish, No thats sadly not working. you want me to do the following right?

    function myprefix_filter_mctb_lists( $lists ) {
    	$list_id_german_list = 'german_id';
    	$list_id_english_list = 'english_id';
    
    	if( defined( 'ICL_LANGUAGE_CODE') ) {
    		switch( ICL_LANGUAGE_CODE ) {
    
    			// german
    			case 'de':
    				$lists = array( $list_id_german_list );
    			break;
    			// english
    			case 'en':
    				$lists = array( $list_id_english_list );
    			break;
    		}
    	}
    	return $lists;
    }
    add_filter( 'mc4wp_lists', 'myprefix_filter_mctb_lists' );

    That doesn’t work, it always signs me in to the list I choose in the Top Bar settings.
    thanks in advance
    Flo

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello Florian,

    I’m sorry I should have been more clearer. Can you please also change “add_filter( ‘mc4wp_lists’, ‘myprefix_filter_mctb_lists’ );” to “add_filter( ‘mctb_lists’, ‘myprefix_filter_mctb_lists’ );”

    Thread Starter flo.ei

    (@floei)

    Hi Harish, No sorry I tried that already, no chance! That code comes into my functions.php right? as last entry?
    thanks for your patience!
    Flo

    Plugin Author Danny van Kooten

    (@dvankooten)

    Hi Flo,

    What does your full code look like and are you sure you’re running WPML to handle your various languages?

    I updated the code a bit so it’s less strict about the language passed by WPML, can you please give this a try?

    <?php
    
    function myprefix_filter_mctb_lists( $default_lists ) {
    	$list_id_german_list = 'german_id';
    	$list_id_english_list = 'english_id';
    	$language_code = defined( 'ICL_LANGUAGE_CODE' ) ? strtolower( ICL_LANGUAGE_CODE ) : '';
    
    	if( $language_code === 'de' ) {
    		return array( $list_id_german_list );
    	}
    
    	if( $language_code === 'en' ) {
    		return array( $list_id_english_list );
    	}
    
    	return $default_lists;
    }
    
    add_filter( 'mctb_lists', 'myprefix_filter_mctb_lists' );

    Let me know please!

    Please note that if you’re not running WPML, we have to adjust the logic of the code. So let us know which Multilingual plugin you’re running please. πŸ™‚

    Thread Starter flo.ei

    (@floei)

    Hi Danny thanks for your answer. Yes I use WPML, really sure πŸ˜‰
    Problem seems to be that it is not running the function, because even if i pass the english list as a return value of all of the cases, it signs me in to the default list.

    I put it into the functions.php of my theme, this is correct no?

    Enis

    (@enistrevisi)

    Is there a way to apply the same filter to the ninja forms integration for Mailchimp for wordpress?

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Different List for different Language’ is closed to new replies.