er( $wp_taxonomies[ $taxonomy ]->labels->name ) . '',
'' . mb_strtolower( $wp_post_types[ $object_type ]->labels->name ) . ''
) . '' .
'
';
$out .= '';
} else {
$out .= sprintf(
/* translators: %1$s is a taxonomy name and %2$s is a post type name */
__( 'All %1$s have the same %2$s assignments.', 'woocommerce-multilingual' ),
'' . mb_strtolower( $wp_taxonomies[ $taxonomy ]->labels->name ) . '',
'' . mb_strtolower( $wp_post_types[ $object_type ]->labels->name ) . ''
);
}
$out .= '';
} else {
$out .= sprintf(
/* translators: %1$s is a taxonomy name and %2$s is a post type name */
__( 'Successfully updated %1$s for all translated %2$s.', 'woocommerce-multilingual' ),
$wp_taxonomies[ $taxonomy ]->labels->name,
$wp_post_types[ $object_type ]->labels->name
);
}
return $out;
}
/**
* Filter shipping terms
*
* @param WP_Term[]|false|WP_Error $terms Terms to filter.
* @param int $post_id Post ID.
* @param string $taxonomy Taxonomy.
*
* @return WP_Term[]|false|WP_Error
*/
public function shipping_terms( $terms, $post_id, $taxonomy ) {
global $pagenow;
if (
'post.php' === $pagenow ||
self::PRODUCT_SHIPPING_CLASS !== $taxonomy ||
( isset( $_POST['action'] ) && 'woocommerce_load_variations' === $_POST['action'] ) ) {
return $terms;
}
$post_type = get_post_type( $post_id );
if ( ! in_array( $post_type, [ 'product', 'product_variation' ], true ) ) {
return $terms;
}
$current_language = $this->sitepress->get_current_language();
$key = md5( wp_json_encode( [ $post_id, $current_language ] ) );
$found = false;
$terms = WPML_Non_Persistent_Cache::get( $key, __CLASS__, $found );
if ( ! $found ) {
remove_filter( 'get_the_terms', [ $this, 'shipping_terms' ], 10 );
$terms = get_the_terms(
apply_filters( 'wpml_object_id', $post_id, $post_type, true, $current_language ),
self::PRODUCT_SHIPPING_CLASS
);
add_filter( 'get_the_terms', [ $this, 'shipping_terms' ], 10, 3 );
WPML_Non_Persistent_Cache::set( $key, $terms, __CLASS__ );
}
return $terms;
}
public function filter_shipping_classes_terms( $terms, $taxonomies, $args ) {
if ( $taxonomies && is_admin() && in_array( self::PRODUCT_SHIPPING_CLASS, $taxonomies ) ) {
$on_wc_settings_page = isset( $_GET['page'] ) && \WCML\Utilities\AdminUrl::PAGE_WOO_SETTINGS === $_GET['page'];
$on_shipping_tab = isset( $_GET['tab'] ) && $_GET['tab'] === 'shipping';
$on_classes_section = isset( $_GET['section'] ) && $_GET['section'] === 'classes';
if ( $on_wc_settings_page && $on_shipping_tab && ! $on_classes_section ) {
remove_filter( 'get_terms', [ $this, 'filter_shipping_classes_terms' ] );
$this->sitepress->switch_lang( $this->sitepress->get_default_language() );
$terms = get_terms( $args );
add_filter( 'get_terms', [ $this, 'filter_shipping_classes_terms' ], 10, 3 );
$this->sitepress->switch_lang();
}
}
return $terms;
}
public function wcml_delete_term( $term, $tt_id, $taxonomy, $deleted_term ) {
global $wp_taxonomies;
foreach ( $wp_taxonomies as $key => $taxonomy_obj ) {
if ( ( in_array( 'product', $taxonomy_obj->object_type ) || in_array( 'product_variation', $taxonomy_obj->object_type ) ) && $key == $taxonomy ) {
$this->update_terms_translated_status( $taxonomy );
break;
}
}
}
/**
* @param array $terms
* @param int $product_id
* @param string $taxonomy
* @param array $args
*
* @return array
*/
public function get_product_terms_filter( $terms, $product_id, $taxonomy, $args ) {
$language = $this->sitepress->get_language_for_element( $product_id, 'post_' . get_post_type( $product_id ) );
$is_objects_array = is_object( current( $terms ) );
$filtered_terms = [];
foreach ( $terms as $term ) {
if ( ! $is_objects_array ) {
$term_obj = get_term_by( 'name', $term, $taxonomy );
$is_wc_filtering_by_slug = isset( $args['fields'] ) && in_array( $args['fields'], [ 'id=>slug', 'slugs' ] );
if ( $is_wc_filtering_by_slug || ! $term_obj ) {
$term_obj = get_term_by( 'slug', $term, $taxonomy );
$is_slug = true;
}
}
if ( empty( $term_obj ) ) {
$filtered_terms[] = $term;
continue;
}
$trnsl_term_id = apply_filters( 'wpml_object_id', $term_obj->term_id, $taxonomy, true, $language );
if ( $is_objects_array ) {
$filtered_terms[] = get_term( $trnsl_term_id, $taxonomy );
} else {
if ( isset( $is_slug ) ) {
$filtered_terms[] = get_term( $trnsl_term_id, $taxonomy )->slug;
} else {
$filtered_terms[] = ( wp_doing_ajax() && isset( $_POST['action'] ) && in_array(
$_POST['action'],
[
'woocommerce_add_variation',
'woocommerce_link_all_variations',
]
) ) ? strtolower( get_term( $trnsl_term_id, $taxonomy )->name ) : get_term( $trnsl_term_id, $taxonomy )->name;
}
}
}
return $filtered_terms;
}
public function set_flag_to_sync( $taxonomy, $el_id, $language_code ) {
if ( $el_id ) {
$elem_details = $this->sitepress->get_element_language_details( $el_id, 'tax_' . $taxonomy );
if ( null !== $elem_details->source_language_code ) {
$this->check_if_sync_term_translation_needed( $el_id, $taxonomy );
}
}
}
public function check_if_sync_terms_needed() {
$wcml_settings = $this->woocommerce_wpml->get_settings();
$wcml_settings['sync_variations'] = 0;
$wcml_settings['sync_product_cat'] = 0;
$wcml_settings['sync_product_tag'] = 0;
$wcml_settings['sync_product_shipping_class'] = 0;
$this->woocommerce_wpml->update_settings( $wcml_settings );
$taxonomies_to_check = [ WCTaxonomies::TAXONOMY_PRODUCT_CATEGORY, WCTaxonomies::TAXONOMY_PRODUCT_TAG, self::PRODUCT_SHIPPING_CLASS ];
foreach ( $taxonomies_to_check as $check_taxonomy ) {
$terms = get_terms(
$check_taxonomy,
[ 'hide_empty' => false ]
);
if ( is_array( $terms ) ) {
/** @var WP_Term $term */
foreach ( $terms as $term ) {
if ( $this->check_if_sync_term_translation_needed( $term->term_taxonomy_id, $check_taxonomy ) ) {
break;
}
}
}
}
$attribute_taxonomies = wc_get_attribute_taxonomies();
$flag_set = false;
foreach ( $attribute_taxonomies as $a ) {
$terms = get_terms(
WCTaxonomies::TAXONOMY_PREFIX_ATTRIBUTE . $a->attribute_name,
[ 'hide_empty' => false ]
);
if ( is_array( $terms ) ) {
/** @var WP_Term $term */
foreach ( $terms as $term ) {
$flag_set = $this->check_if_sync_term_translation_needed( $term->term_taxonomy_id, WCTaxonomies::TAXONOMY_PREFIX_ATTRIBUTE . $a->attribute_name );
if ( $flag_set ) {
break;
}
}
}
if ( $flag_set ) {
break;
}
}
}
public function check_if_sync_term_translation_needed( $t_id, $taxonomy ) {
$wcml_settings = $this->woocommerce_wpml->get_settings();
$attribute_taxonomies = wc_get_attribute_taxonomies();
$attribute_taxonomies_arr = [];
foreach ( $attribute_taxonomies as $a ) {
$attribute_taxonomies_arr[] = WCTaxonomies::TAXONOMY_PREFIX_ATTRIBUTE . $a->attribute_name;
}
if ( ( isset( $wcml_settings[ 'sync_' . $taxonomy ] ) && $wcml_settings[ 'sync_' . $taxonomy ] ) || ( in_array( $taxonomy, $attribute_taxonomies_arr ) && isset( $wcml_settings['sync_variations'] ) && $wcml_settings['sync_variations'] ) ) {
return true;
}
$translations = $this->wpdb->get_results( $this->wpdb->prepare( "SELECT t2.element_id, t2.source_language_code FROM {$this->wpdb->prefix}icl_translations AS t1 LEFT JOIN {$this->wpdb->prefix}icl_translations AS t2 ON t1.trid = t2.trid WHERE t1.element_id = %d AND t1.element_type = %s ", $t_id, 'tax_' . $taxonomy ) );
foreach ( $translations as $key => $translation ) {
if ( is_null( $translation->source_language_code ) ) {
$original_count = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT count( object_id ) FROM {$this->wpdb->term_relationships} WHERE term_taxonomy_id = %d ", $translation->element_id ) );
unset( $translations[ $key ] );
}
}
foreach ( $translations as $translation ) {
$count = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT count( object_id ) FROM {$this->wpdb->term_relationships} WHERE term_taxonomy_id = %d ", $translation->element_id ) );
if ( isset( $original_count ) && $original_count != $count ) {
if ( in_array( $taxonomy, [ WCTaxonomies::TAXONOMY_PRODUCT_CATEGORY, WCTaxonomies::TAXONOMY_PRODUCT_TAG, self::PRODUCT_SHIPPING_CLASS ] ) ) {
$wcml_settings[ 'sync_' . $taxonomy ] = 1;
$this->woocommerce_wpml->update_settings( $wcml_settings );
return true;
}
if ( in_array( $taxonomy, $attribute_taxonomies_arr ) ) {
$wcml_settings['sync_variations'] = 1;
$this->woocommerce_wpml->update_settings( $wcml_settings );
return true;
}
}
}
}
public function get_table_taxonomies( $taxonomies ) {
foreach ( $taxonomies as $key => $taxonomy ) {
if ( ! WCTaxonomies::isProductAttribute( $key ) ) {
unset( $taxonomies[ $key ] );
}
}
return $taxonomies;
}
public function get_wc_taxonomies() {
global $wp_taxonomies;
$taxonomies = [];
// don't use get_taxonomies for product, because when one more post type registered for product taxonomy functions returned taxonomies only for product type.
foreach ( $wp_taxonomies as $key => $taxonomy ) {
if (
( in_array( 'product', $taxonomy->object_type ) || in_array( 'product_variation', $taxonomy->object_type ) ) &&
! in_array( $key, $taxonomies )
) {
if ( WCTaxonomies::isProductAttribute( $key ) && ! $this->woocommerce_wpml->attributes->is_translatable_attribute( $key ) ) {
continue;
}
$taxonomies[] = $key;
}
}
return $taxonomies;
}
public function has_wc_taxonomies_to_translate() {
$taxonomies = $this->get_wc_taxonomies();
$no_tax_to_trnls = false;
foreach ( $taxonomies as $taxonomy ) {
$is_fully_translated = 0 === $this->get_untranslated_terms_number( $taxonomy );
if (
! $this->is_translatable_wc_taxonomy( $taxonomy ) ||
$is_fully_translated
) {
continue;
} else {
$no_tax_to_trnls = true;
}
}
return $no_tax_to_trnls;
}
/*
* Use custom query, because get_term_by function return false for terms with "0" slug *
*/
public function wcml_get_term_id_by_slug( $taxonomy, $slug ) {
return $this->wpdb->get_var(
$this->wpdb->prepare(
"SELECT tt.term_id FROM {$this->wpdb->terms} AS t
INNER JOIN {$this->wpdb->term_taxonomy} AS tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy = %s AND t.slug = %s LIMIT 1",
$taxonomy,
sanitize_title( $slug )
)
);
}
public function wcml_get_term_by_id( $term_id, $taxonomy ) {
return $this->wpdb->get_row(
$this->wpdb->prepare(
"
SELECT * FROM {$this->wpdb->terms} t
JOIN {$this->wpdb->term_taxonomy} x
ON x.term_id = t.term_id
WHERE t.term_id = %d AND x.taxonomy = %s",
$term_id,
$taxonomy
)
);
}
public function wcml_get_translated_term( $term_id, $taxonomy, $language ) {
$tr_id = apply_filters( 'wpml_object_id', $term_id, $taxonomy, false, $language );
if ( ! is_null( $tr_id ) ) {
$term_id = $tr_id;
}
return $this->wcml_get_term_by_id( $term_id, $taxonomy );
}
public function is_translatable_wc_taxonomy( $taxonomy ) {
if ( in_array( $taxonomy, [ 'product_type', 'product_visibility' ], true ) ) {
return false;
}
return true;
}
public function pre_option_default_product_cat() {
$lang = $this->sitepress->get_current_language();
$lang = $lang === 'all' ? $this->sitepress->get_default_language() : $lang;
$wcml_settings = $this->woocommerce_wpml->get_settings();
$ttid = isset( $wcml_settings['default_categories'][ $lang ] ) ? (int) $wcml_settings['default_categories'][ $lang ] : 0;
return $ttid === 0
? false : $this->wpdb->get_var(
$this->wpdb->prepare(
"SELECT term_id
FROM {$this->wpdb->term_taxonomy}
WHERE term_taxonomy_id= %d
AND taxonomy='product_cat'",
$ttid
)
);
}
public function update_option_default_product_cat( $oldvalue, $new_value ) {
$new_value = $this->wpdb->get_var( $this->wpdb->prepare( "SELECT term_taxonomy_id FROM {$this->wpdb->term_taxonomy} WHERE taxonomy='product_cat' AND term_id=%d", $new_value ) );
$translations = $this->sitepress->get_element_translations( $this->sitepress->get_element_trid( $new_value, 'tax_product_cat' ) );
$wcml_settings = $this->woocommerce_wpml->get_settings();
if ( ! empty( $translations ) ) {
foreach ( $translations as $t ) {
$wcml_settings['default_categories'][ $t->language_code ] = $t->element_id;
}
if ( isset( $wcml_settings ) ) {
$this->woocommerce_wpml->update_settings( $wcml_settings );
}
}
}
/**
* @param string $key
*
* @return string
*/
public function add_lang_parameter_to_cache_key( $key ) {
return $key . '-' . $this->sitepress->get_current_language();
}
}
Fatal error: Uncaught Error: Class "WCML_Terms" not found in /home/sandrova/public_html/vaniniwpsite/wp-content/plugins/woocommerce-multilingual/classes/class-woocommerce-wpml.php:245
Stack trace:
#0 /home/sandrova/public_html/vaniniwpsite/wp-content/plugins/woocommerce-multilingual/classes/class-woocommerce-wpml.php(203): woocommerce_wpml->init_full(Object(SitePress), Object(wpdb), Object(WooCommerce), Object(WPML_URL_Cached_Converter), Object(WPML_Frontend_Post_Actions), Object(WPML_Term_Translation))
#1 /home/sandrova/public_html/vaniniwpsite/wp-includes/class-wp-hook.php(324): woocommerce_wpml->init('')
#2 /home/sandrova/public_html/vaniniwpsite/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#3 /home/sandrova/public_html/vaniniwpsite/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#4 /home/sandrova/public_html/vaniniwpsite/wp-settings.php(700): do_action('init')
#5 /home/sandrova/public_html/vaniniwpsite/wp-config.php(98): require_once('/home/sandrova/...')
#6 /home/sandrova/public_html/vaniniwpsite/wp-load.php(50): require_once('/home/sandrova/...')
#7 /home/sandrova/public_html/vaniniwpsite/wp-blog-header.php(13): require_once('/home/sandrova/...')
#8 /home/sandrova/public_html/index.php(17): require('/home/sandrova/...')
#9 {main}
thrown in /home/sandrova/public_html/vaniniwpsite/wp-content/plugins/woocommerce-multilingual/classes/class-woocommerce-wpml.php on line 245