WPML
状态
已解决
报告针对
WPML Multilingual & Multicurrency for WooCommerce 4.0.1
解决于
WooCommerce Multilingual 4.0.2

问题概述

问题在于带有变体的产品在原始语言中无法显示变体。该产品的翻译则可以毫无问题地显示所有变体。

请注意,仅当翻译 product_type 分类法时才会出现此问题。完全不应翻译此分类法。

原始语言是您最初创建产品时使用的语言,随后您将其从该语言翻译为站点中的其他语言。

临时解决方法

要修复此问题,您需要执行以下步骤:


  1. 将以下代码添加到您主题的 functions.php 中。

  2. 在前端访问您的网站,并验证产品现在是否正确显示。

  3. functions.php 文件中删除该代码——如果不这样做,可能会导致性能问题
    function fix_product_type_terms(){
        global $wpdb;
        //check if terms were translated
        $translations = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type = 'tax_product_type'" );
 
        if( $translations ){
            foreach( $translations as $translation ){
                if( !is_null( $translation->source_language_code ) ){
                    //check relationships
                    $term_relationships = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $translation->element_id  ) );
                    if( $term_relationships ){
                        $orig_term = $wpdb->get_var( $wpdb->prepare( "SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type = 'tax_product_type' AND trid = %d AND source_language_code IS NULL", $translation->trid ) );
                        if( $orig_term ){
                            foreach( $term_relationships as $term_relationship ){
                                $wpdb->update(
                                    $wpdb->term_relationships,
                                    array(
                                        'term_taxonomy_id' => $orig_term
                                    ),
                                    array(
                                        'object_id' => $term_relationship->object_id,
                                        'term_taxonomy_id' => $translation->element_id
                                    )
                                );
                            }
                        }
                    }
                    $term_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = %d", $translation->element_id  ) );
 
                    if( $term_id ){
                        $wpdb->delete(
                            $wpdb->terms,
                            array(
                                'term_id' => $term_id
                            )
                        );
 
                        $wpdb->delete(
                            $wpdb->term_taxonomy,
                            array(
                                'term_taxonomy_id' => $translation->element_id
                            )
                        );
                    }
                }
            }
 
            foreach( $translations as $translation ){
                $wpdb->delete(
                    $wpdb->prefix . 'icl_translations',
                    array(
                        'translation_id' => $translation->translation_id
                    )
                );
            }
        }
    }
add_action( 'init' , 'fix_product_type_terms' );

所有已知问题 →