Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to code PHP as per current language?

Solution:
You have to use "ICL_LANGUAGE_CODE" to get your current language.
Here is the sample code/structure

function my_custom_function() {
    if(ICL_LANGUAGE_CODE=='en'){
        <!--- your code to english--->
      
    } elseif(ICL_LANGUAGE_CODE=='de'){
        <!---your code to german--->
  
  
    } elseif(ICL_LANGUAGE_CODE=='fr'){
        <!---your code to french---
        Global site tag (gtag.js) - Google Analytics -->
  
    } elseif(ICL_LANGUAGE_CODE=='es'){
        <!---your code to spanish--->
    }
}

Modify your code according to this and you will get what you want.

60% of people find this useful.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by grzegorzS-19 4 years, 3 months ago.

Assisted by: Riffaz.

Author Posts
June 22, 2020 at 4:32 pm #6428251

grzegorzS-19

Hello,

I am customizing the "my account" page in Woocommerce

I use my own php code to add bookmarks to the "my account" menu. The content of the added bookmarks is displayed using shortcode to custom html blocks.

Wmpl doesn't explain these bookmarks and some content from custom html blocks to me. I tried various settings including scanning while rendering pages.

I thought that I could make custom php separate for each language, thus creating dedicated content for individual languages, and that's why I need help.

How to modify php code to make it active only for a given language?

My code looks like this:

/*
* Dodanie Ankiety pacjenta
*/

function add_ankieta_pacjenta_endpoint() {
add_rewrite_endpoint( 'ankieta-pacjenta', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'add_ankieta_pacjenta_endpoint' );

function ankieta_pacjenta_query_vars( $vars ) {
$vars[] = 'ankieta-pacjenta';
return $vars;
}
add_filter( 'query_vars', 'ankieta_pacjenta_query_vars', 0 );

function add_ankieta_pacjenta_link_my_account( $items ) {
$items['ankieta-pacjenta'] = 'Ankieta pacjenta';
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'add_ankieta_pacjenta_link_my_account' );

function ankieta_pacjenta_content() {
echo do_shortcode('[html_block id="4921"]');
}
add_action( 'woocommerce_account_ankieta-pacjenta_endpoint', 'ankieta_pacjenta_content');

June 23, 2020 at 3:35 am #6430953

Riffaz

Hi,

Thank you for contacting WPML support.

You have to use "ICL_LANGUAGE_CODE" to get your current language.
Here is the sample code/structure

function my_custom_function() {
    if(ICL_LANGUAGE_CODE=='en'){
        <!--- your code to english--->
     
    } elseif(ICL_LANGUAGE_CODE=='de'){
        <!---your code to german--->
 
 
    } elseif(ICL_LANGUAGE_CODE=='fr'){
        <!---your code to french---
        Global site tag (gtag.js) - Google Analytics -->
 
    } elseif(ICL_LANGUAGE_CODE=='es'){
        <!---your code to spanish--->
    }
}

Modify your code according to this and you will get what you want.

Let me know the results, please.

Regards,
Riffaz.

June 23, 2020 at 11:04 am #6433921

grzegorzS-19

Thank you very much,
I have modified my php and it works. thank you again.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.