Hi there,
in which file you find this code?
Hi there,
ok, now I understand the request. You should try to override the template in the theme and change this code in this way (or something similar):
echo '<span class="attribute-' . $field . '">' . empty( $product->fields[ $field ] ) ? ' ' : $product->fields[ $field ] . '</span>';
To override the template on your theme simply copy this file: https://plugins.trac.wordpress.org/browser/yith-woocommerce-compare/trunk/templates/compare.php in wp-content/themes/your-theme-folder/woocommerce/compare.php.
Let me know if works.
Hi,
thanks for the code snippet you shared. But unfortunately this is not what I had in mind.
Your code helped to achieve this attribute-blablabla:
<tr class="pa_blablabla different odd">
<th>Bla bla bla</th>
<td class="odd product_9860"> - </td>
<td class="even product_9992">
<span class="attribute-blablabla">Red</span>, <span class="attribute-blablabla">Green</span>
</td>
</tr>
But I need to get this: blablabla-red, blablabla-green and more… I need ‘Blablabla’ (from ‘pa_blablabla’) + ‘-‘ + ‘slug value’.
<tr class="pa_blablabla different odd">
<th>Bla bla bla</th>
<td class="odd product_9860"> - </td>
<td class="even product_9992">
<span class="blablabla-red">Red</span>, <span class="blablabla-green">Green</span>
</td>
</tr>
Thanks
Hello,
Please use this code instead:
$attribute = get_term_by( 'name', $product->fields[ $field ], $field, 'ARRAY_A' );
if ( $attribute ) {
echo '<span class="' . $field . '-' . $attribute['slug'] . '">' . ( empty( $product->fields[ $field ] ) ? ' ' : $product->fields[ $field ] ) . '</span>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
echo empty( $product->fields[ $field ] ) ? ' ' : $product->fields[ $field ]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
break;
So this code checks if it’s an attribute and will get the slug of term, creating the span that you requested.
Let me know if it works in your site.
Hi there,
Since we have not received a reply on your side, we will proceed to set this inquiry as resolved. However, for further assistance, do not hesitate to open a new thread.
Have a great day!
Hi @pperez001,
I apologize for the long absence, our region is very turbulent right now.
I have nothing worked out. Could you please write exactly what to replace with your code?
Hello,
You just have to replace the part my colleague sent you:
echo '<span class="attribute-' . $field . '">' . empty( $product->fields[ $field ] ) ? ' ' : $product->fields[ $field ] . '</span>';
With the one this other:
$attribute = get_term_by( 'name', $product->fields[ $field ], $field, 'ARRAY_A' );
if ( $attribute ) {
echo '<span class="' . $field . '-' . $attribute['slug'] . '">' . ( empty( $product->fields[ $field ] ) ? ' ' : $product->fields[ $field ] ) . '</span>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} else {
echo empty( $product->fields[ $field ] ) ? ' ' : $product->fields[ $field ]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
break;
Let me know you encounter any problem and have a great day.