Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
Product Attribute image not copied for translation in Vega theme.

Solution:
- Backup the website and database (important)
- Go to WPML -> Settings page , scroll to "Custom Fields Translation" section.
- Click on the "Show system fields" link and set the field "_xts_attribute_image" to copy.
- Add the following code to your theme functions.php file and replace the $taxonomy value "pa_color" in line 9 with the taxonomy/attribute name with the issue.

/**
 * WPML Workaround for compsupp-6299
 */
add_action('wp_head', 'wpml_compsupp6299_replace_term_meta_on_translations'); 
 
function wpml_compsupp6299_replace_term_meta_on_translations() { 
 
    // Settings
    $taxonomy = 'pa_color'; // Replace with the attribute taxonomy
    $term_meta_key = '_xts_attribute_image'; //Replace with the term meta key
 
    //Get Terms
    $terms = get_terms(array(
        'taxonomy' => $taxonomy,
        'hide_empty' => false,
    ) );
 
    echo '<div style="margin: 20px auto; border-radius: 20px; width: 800px; padding: 20px; border: 4px solid #ff0000;">';
     
    foreach ( $terms as $term ) {
        $term_meta_value = get_term_meta( $term->term_id, $term_meta_key, true );
 
        //Get Translations
        $taxonomy_wpml_key = 'tax_'.$taxonomy;
        $trid = apply_filters( 'wpml_element_trid', NULL, $term->term_id, $taxonomy_wpml_key );
        $translations = apply_filters( 'wpml_get_element_translations', NULL, $trid, $taxonomy_wpml_key);
 
         
        foreach ($translations as $translation) {
            $translation_id = intval($translation->element_id);
 
            // Update term meta on translations with the meta value from the original term
            if ($translation_id != $term->term_id ) {
                update_term_meta( $translation_id, $term_meta_key, $term_meta_value );
                 
                echo '<h4>Term '.$translation_id.' updated.</h4>';              
                echo '<hr/>';
            }
        }
         
    }
    echo '<p>Please remove the workaround from the functions.php file.';
    echo '</div>';    
}

- Visit the site on front-end which will execute the code and the values from _xts_attribute_image term meta will be copied to the translations of the taxonomy/attributes.
- Do this for all Attribute names with the issue.
- Delete the code from the functions.php file.

Relevant Documentation:
N/A

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 20 replies, has 2 voices.

Last updated by John 1 year, 10 months ago.

Assisted by: Subash Chandra Poudel.

Author Posts
June 25, 2022 at 5:07 pm #11543369

Subash Chandra Poudel

Hi there,

Thank you for the updates.

On your staging site when I followed the exact steps as I explained in my previous reply linked next it works fine

https://wpml.org/forums/topic/issue-with-wpml-and-product-attributes/#post-11531363

The "Copy to all language" option is not required to fix the issue as I see on your staging site and as I explained. Since you have now set the attribute fields to copy on the live site, doing the second and third steps from my previous reply for the attributes with issues should fix the issue.

However, I see your staging site is not exactly the same as the live site. If the workaround is not working on your live site, please clone your current live site to the staging site and let me know along with the new details to access the staging site ( I have enabled the private reply for you to share the details safely). I can then further test it on the staging site to see why it is not working or how to fix it.

Regards,
Subash

June 27, 2022 at 12:59 pm
June 27, 2022 at 2:48 pm #11552583

Subash Chandra Poudel

Hi there,

Can you please also let me know an attribute name or link on the site that is having the issue of attribute image not being copied to the translation?

Regards,
Subash

June 27, 2022 at 2:52 pm #11552651

John

Hello,
Here is the exacted link hidden link
Waiting for your replay,
Thank you!

June 27, 2022 at 4:50 pm #11553671

Subash Chandra Poudel

Hi there,

After further testing the issue I can again replicate the issue of Attribute images not being copied to translation on your new staging site and also on our sandbox site.

I have now escalated the issue to our 2'nd tier team to investigate the issue in detail and see if this can be fixed from our end.

I will send you to keep you updated on any updates from our team which might take some time as our 2'nd tier team deals with complex and edge case issues and needs some time to fully test the issue. Thank you for your patience in the meantime.

Regards,
Subash

June 30, 2022 at 8:35 am #11573407

Subash Chandra Poudel

Hi there,

We have an update from our 2'nd tier team.

This seems to be a known issue and our developers are already working on it to provide a fix in the future WPML releases. We don't have an ETA for the fix yet though.

Please follow the following workaround to bulk copy the _xts_attribute_image field to the taxonomy/attribute translations.

- Backup the website and database (important)

- Add the following code to your theme functions.php file and replace the $taxonomy value "pa_color" in line 9 with the taxonomy/attribute name with the issue.

/**
 * WPML Workaround for compsupp-6299
 */
add_action('wp_head', 'wpml_compsupp6299_replace_term_meta_on_translations'); 

function wpml_compsupp6299_replace_term_meta_on_translations() { 

	// Settings
	$taxonomy = 'pa_color'; // Replace with the attribute taxonomy
	$term_meta_key = '_xts_attribute_image'; //Replace with the term meta key

	//Get Terms
	$terms = get_terms(array(
		'taxonomy' => $taxonomy,
		'hide_empty' => false,
	) );

	echo '<div style="margin: 20px auto; border-radius: 20px; width: 800px; padding: 20px; border: 4px solid #ff0000;">';
	
	foreach ( $terms as $term ) {
		$term_meta_value = get_term_meta( $term->term_id, $term_meta_key, true );

		//Get Translations
		$taxonomy_wpml_key = 'tax_'.$taxonomy;
		$trid = apply_filters( 'wpml_element_trid', NULL, $term->term_id, $taxonomy_wpml_key );
		$translations = apply_filters( 'wpml_get_element_translations', NULL, $trid, $taxonomy_wpml_key);

		
		foreach ($translations as $translation) {
			$translation_id = intval($translation->element_id);

			// Update term meta on translations with the meta value from the original term
			if ($translation_id != $term->term_id ) {
				update_term_meta( $translation_id, $term_meta_key, $term_meta_value );
				
				echo '<h4>Term '.$translation_id.' updated.</h4>';				
				echo '<hr/>';
			}
		}
		
	}
	echo '<p>Please remove the workaround from the functions.php file.';
	echo '</div>';	
}

- Visit the site on front-end which will execute the code and the values from _xts_attribute_image term meta will be copied to the translations of the taxonomy/attributes.

- Do this for all Attribute names with the issue.

- Delete the code from the functions.php file.

Regards,
Subash

June 30, 2022 at 12:02 pm #11575927

John

Hello,
We are going to try the fix later this day.
Many thanks for your help.
I would like to know if the 2nd tier support cand also check the previous problem with product template. Maybe he will find a way to translate it correctly without the workaround.
Many thanks

June 30, 2022 at 1:35 pm #11577073

Subash Chandra Poudel

Hi there,

Please let me know how it goes after trying the workaround.

Also, note in the third step above "- Visit the site on front-end .." you should visit the site frontend in the primary language.

As for the template issue, since I have already suggested a fix for you on the ticket https://wpml.org/forums/topic/split-product-template-with-vega-theme/ and that is the standard method to translate data stored by themes in wp_options table I don't think there is anything our 2'nd support tier team can do there.

Regards,
Subash

July 3, 2022 at 7:47 pm #11593319

John

My issue is resolved now. Thank you and really appreciate your implication in finding the solution for my issues.
Hope the fix will come soon and fix this kind of time-consuming bug.
All the best!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.