Skip Navigation

Resolved

Reported for: WooCommerce Multilingual & Multicurrency 4.0.1

Resolved in: WooCommerce Multilingual 4.0.2

Overview of the issue

The problem is with a product with variations not displaying variations in the original language. The translations of that product display all the variations without a problem.

Please note that this issue occurs only when the product_type taxonomy is translated. This taxonomy should not be translated at all.

Original language is the language which you originally created the product in, and then translated it from that language to other languages in your site.

Workaround

To fix this, you need to use the following steps:

  1. Add the code found below to your theme’s functions.php.
  2. Visit your site on the front-end and verify that the product is now correctly displayed.
  3. Remove the code from the functions.php file – not doing so may result in performance issues.
    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' );

 

15 Responses to “Product with variations does not display variation in original language”

  1. This fixed the issue. Thank you!

    Could you please elaborate how this problem was created in the first place, in order to avoid it in the future?

    • I think that I have already mentioned in your ticket, for this issue that it should not happen in the future and we are going to add a warning that warns when something like that happens.
      This happened because at some time (maybe before installing WCML) the product_type taxonomy was set as translatable and the “Variation” term was translated.
      This is not how WCML handles the situation at this time, and we force product_type taxonomy to be not translated, however the entries with the translation remain in icl_translations table – and this causes the problem.

  2. Yes, this workaround fixed the issue for me too. I’m still not clear, however, on the cause of the problem. My site was working fine for several weeks before the problem arose. Thanks for any additional info!

    • Hello and thank you for contacting us.
      If you are having the same problem, then you should have a message in the admin part of the site that should lead you to the WooCommerce Multilingual troubleshooting options where you can fix it by pressing one button.
      We added detection about that issue since WooCommerce Multilingual 4.0.2

      If you don’t see that message, then I would suggest that you open a new ticket in our forum here so that we investigate the issue – it might look like the one reported here – but it could be a totally different issue – especially if other products in the second language work.

      • If the other products with variations in the same language work – then it is another problem.
        The easiest way to fix this is to try and re-create the product and its variations. If you wish that we investigate other options, or if this does not help – then please consider opening a ticket in our forum where our experts will help you with resolving the problem.

        Best regards