get_current_language(); $default_language = $sitepress->get_default_language(); if ( $current_lang !== $default_language ) { $sitepress->switch_lang( $default_language ); $tax = get_terms( array( 'taxonomy' => $tax_name, 'hide_empty' => false, ) ); if ( ! empty( $tax ) ) { foreach ( $tax as $tax_item ) { $options[$tax_item->term_id] = $tax_item->name; } } $sitepress->switch_lang( $current_lang ); } } return $options; } /* * Fix condition rules for product taxonomies */ public function tax_condition_rule( $condition_rule ) { $condition_name = $condition_rule['param']; $tax_name = ''; if ( $condition_name === 'product_category' ) { $tax_name = 'product_cat'; } elseif ( $condition_name === 'product_tag' ) { $tax_name = 'product_tag'; } elseif ( $condition_name === 'product_taxonomy' || $condition_name === 'product_attributes' ) { $tax_name = isset( $condition_rule['suboption'] ) ? $condition_rule['suboption'] : ''; } if ( $tax_name ) { global $sitepress; if ( $sitepress ) { $current_lang = $sitepress->get_current_language(); $value = isset( $condition_rule['value'] ) ? $condition_rule['value'] : ''; if ( is_array( $value ) ) { $translated = array(); foreach ( $value as $term_id ) { $trid = $sitepress->get_element_trid( intval( $term_id ), 'tax_' . $tax_name ); if ( $trid ) { $translations = $sitepress->get_element_translations( $trid, 'tax_' . $tax_name ); if ( $translations && isset( $translations[ $current_lang ] ) ) { $translated[] = $translations[ $current_lang ]->element_id; continue; } } $translated[] = $term_id; } $condition_rule['value'] = $translated; } else { $trid = $value ? $sitepress->get_element_trid( intval( $value ), 'tax_' . $tax_name ) : false; if ( $trid ) { $translations = $sitepress->get_element_translations( $trid, 'tax_' . $tax_name ); if ( $translations && isset( $translations[ $current_lang ] ) ) { $condition_rule['value'] = $translations[ $current_lang ]->element_id; } } } } } return $condition_rule; } /* * Fix condition rules for products */ public function product_condition_rule( $condition_rule ) { if ( $condition_rule['param'] === 'product' ) { global $sitepress; if ( $sitepress ) { $current_lang = $sitepress->get_current_language(); $trid = isset( $condition_rule['value'] ) ? $sitepress->get_element_trid( intval( $condition_rule['value'] ), 'post_product' ) : false; if ( $trid ) { $translations = $sitepress->get_element_translations( $trid, 'post_product' ); if ( $translations && isset( $translations[$current_lang] ) ) { $term_trans = $translations[$current_lang]; $condition_rule['value'] = $term_trans->element_id; } } } } return $condition_rule; } } endif; AWL_WPML::instance();