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 4 replies, has 2 voices.

Last updated by Radu 1 month, 1 week ago.

Assigned support staff: Radu.

Author Posts
September 3, 2019 at 3:49 pm #4506003

Boris

I have a WPML/WooCommerce website of one of my clients. They use a variety of product attributes. These have all been set properly in Woocommerce and translated via WooCommerce Multilingual.

However, on both the Dutch (default language) and English pages, attributes are shown.

They are using the following piece of code in their theme to display these attributes:

// Output title and product additional information in right location
function woocommerce_template_additional_info_html() {
global $product;
$prod_atts = $product->get_attributes();
//var_dump($prod_atts);
$output = '';
$output = '<div class="product_row">';
$output.= '<div class="product_information">';
$output.= '<div class="wrap">';
$output.= '<h1>'.get_the_title().'</h1>';
$output.= '<div class="product_attributes">';
$output.= '<h2>'.__('Eigenschappen','divtag').'</h2>';
$output.= '<div class="attributes_table">';
foreach ( $prod_atts as $attribute ) {
if ( $attribute['is_taxonomy'] ) {
$terms = wp_get_post_terms( $product->id, $attribute['name'], 'all' );
// get the taxonomy
$tax = $terms[0]->taxonomy;
// get the tax object
$tax_object = get_taxonomy($tax);
// get tax label
foreach ( $terms as $term ) {
if ( isset ($tax_object->labels->name) ) {
$tax_label = $tax_object->labels->singular_name;
} elseif ( isset( $tax_object->label ) ) {
$tax_label = $tax_object->label;
}
$output.='<div class="attr_row">';
$output.='<div class="attr_name">'.$tax_label.'</div>';
$output.='<div class="attr_value">'.$term->name.'</div>';
$output.='</div>';
}
} else {
$output.='<div class="attr_row custom">';
$output.='<div class="attr_name">'.$attribute["name"].'</div>';
$output.='<div class="attr_value">'.$attribute["value"].'</div>';
$output.='</div>';
}
}
$output.= '</div>';
$output.= '</div>';
$output.= '</div>';
echo $output;
}

When I disable the theme in favour of 2019, the translations show up correctly. Also, it worked fine until some time ago (last time I'm sure is about one year ago). They claim they have not changed any of the code in the theme.

So most likely it is something in the theme that has stopped working after a WooCommerce update.

Can you have a look at the code above, and try and help me fix this?

Thanks!
Kind regards
Boris

September 3, 2019 at 7:20 pm #4507071

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Boris,

It's hard to say what's the issue, especially when it's only happening on some custom code. Can you tell me where is this woocommerce_template_additional_info_html function used? Also, what's the value returned by the $product->get_attributes() code when accessing the secondary language? I also checked the get_attributes function and it doesn't seem to be changed lately (the last time it was changed in 2016).

Thanks,
Radu

September 4, 2019 at 7:26 am #4508745

Boris

Hi Radu,
thanks for your help!
The woocommerce_template_additional_info_html function is used here: hidden link
To show the grey block with the specifications. These are the items that are not translated to English on the front end.
As you can see there, the $product->get_attributes() results in showing the labels (column starting with product group) and the values (column starting with pot alstroemeria).
Regards,
Boris

September 4, 2019 at 7:35 am #4508775

Boris

I just did a small test, and replaced the code snippet I pasted in the inital ticket with the default code to echo attributes:
global $product;
echo wc_display_product_attributes( $product );
The translations are shown then.
Solving it this way is not an option, I'm afraid, but it's certain now that the fault lies within that code snippet. Do you see the flaw in there?

September 4, 2019 at 12:45 pm #4511157

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hey Boris,

It's hard to tell what wrong on the custom code you attached on your first reply. As you may know, helping with custom code is outside of our support scope.

What I would do is take each part of the code that's retrieving some content (like $tax = $terms[0]->taxonomy;, for example), and see what's the returned value (using var_dump). This way, you'll be able to identify what's the part that's not working as expected and then check the WooCommerce documentation to see if anything changed in the last updates.

Thanks,
Radu

The topic ‘[Closed] Translated product attributes are not showing on the product page’ is closed to new replies.