Budget: 500 UAH Deadline: 1 day
Зараз зроблю, аж самому стало цікаво :)
Можна тестувати. Локально працює.
function get_terms_by_lang( $lang = '' ) {
global $sitepress;
$current_lang = apply_filters( 'wpml_current_language', null );
if ( $lang ) {
// Switch the language to ... before the get_terms
$sitepress->switch_lang( $lang );
}
$data_terms = [];
$terms = get_terms( [
'taxonomy' => 'product_cat',
'hide_empty' => 'false',
] );
foreach ( $terms as $term ) {
$data_terms[] = [
'lang' => $lang,
'title' => $term->name,
'category_id' => $term->term_id,
];
}
if ( $lang ) {
// Check if the terms are expected and then switch back the language
$sitepress->switch_lang( $current_lang );
}
return $data_terms;
}