Posts

Showing posts from December, 2013

WPML & Woocommerce: How to select product of other languages in PHP?

If you are looking for a way that, by using PHP, you want to find out what product ID of other languages are, here is the code:

if(function_exists('icl_get_languages')){
    $available_langs = icl_get_languages('skip_missing=0');
foreach($available_langs as $lang){
$lang_post_id = icl_object_id($existing_post_id, 'product', true, $lang['language_code']);
if(empty($lang_post_id) == FALSE){
/** * Do whatever you want here... /**/
}
}
}


Here is how this work:

Check if WPML is installed by checking if icl_get_languages exists. I am getting all langs here (skip_missing=0).Use icl_get_languages to get ALL languagesUse a loop to check existing language with language code. If that product exists, it will return a product ID, otherwise, it is NULL (Source).Use conditional statement to continue processing if $lang_post_id is not NULL Hope it helps someone.