I'm using the following code to check if a product in the loop has a certain taxonomy (product cat) assigned:
{!{wpv-conditional if="( CONTAINS(#(product_cat),'schallwandler') )"}!}TEST[/wpv-conditional]
{!{wpv-conditional debug="true" if="( has_term('schallwandler', 'product_cat', null) eq '1' )"}!}TEST[/wpv-conditional]
[wpv-conditional if="('[wpv-post-taxonomy type='product_cat' format='slug' ]' eq 'schallwandler' )"]TEST[/wpv-conditional]
This works great on the main language but does not work on the transalted counterpart.
This is the debug info:
####################
wpv-conditional attributes
####################
Array
(
[debug] => true
[if] => ( CONTAINS(#(product_cat),schallwandler) )
)
####################
Debug information
####################
--------------------
Original expression: ( CONTAINS(#(product_cat),schallwandler) )
--------------------
After matching 2 numeric strings into real numbers: ( CONTAINS(ARRAY('microphones-haut-parleurs-fr-2',209,'Microphones haut-parleurs','transducteurs','201','Transducteurs'),schallwandler) )
Matched '209' to 209
After matching 5 numeric strings into real numbers: ( CONTAINS(ARRAY('microphones-haut-parleurs-fr-2',209,'Microphones haut-parleurs','transducteurs',201,'Transducteurs'),schallwandler) )
Matched '201' to 201
####################
wpv-conditional attributes
####################
Array
(
[debug] => true
[if] => ( has_term('schallwandler', 'product_cat', null) = 1 )
)
####################
Debug information
####################
--------------------
Original expression: ( has_term('schallwandler', 'product_cat', null) = 1 )
I would expect that it automatically checks for the translated string.
I don't want to add the translated strings in all my conditional logics.
Nigel
Supporter
Sprachen:
Englisch (English )
Spanisch (Español )
Zeitzone:
Europe/London (GMT+00:00)
I also would expect that the translations should be compared automatically, but found on my test site that they are not.
I'm raising an internal ticket about this, but in the meantime I considered how to get it to work.
You can register a custom shortcode to get the term that you want to check.
That seems a bit redundant, but WPML filters the call to the function get_term_by so that it returns the translated term.
So try registering this custom shortcode:
add_shortcode('translated', function ($atts = []) {
// provide defaults
$atts = shortcode_atts(
array(
'term' => null,
'tax' => null
),
$atts
);
$term = get_term_by( 'slug', $atts['term'], $atts['tax'] );
return $term->slug;
});
And here's an example of my using it where I specify the term is 'red' and belongs to the taxonomy 'colour':
<p>Conditionally: [wpv-conditional if="( CONTAINS(#(colour),'[translated term='red' tax='colour']') )"]It's red[/wpv-conditional]</p>
Thank you Nigel. I will use your shortcode until this is fixed. Is there a link where I can track the status of the issue?
Nigel
Supporter
Sprachen:
Englisch (English )
Spanisch (Español )
Zeitzone:
Europe/London (GMT+00:00)
Let me re-open this for now, and when it's handled by second tier there should be an erratum created which you can watch.
I'll post another update when I see how this progresses.
Nigel
Supporter
Sprachen:
Englisch (English )
Spanisch (Español )
Zeitzone:
Europe/London (GMT+00:00)
We discussed this between supporters and developers and decided there were too many ways that implementing this automatically could introduce problems, and so we won't be making any changes.
Please continue to use the custom shortcode that I provided.
An alternative would be to create different content templates for each language, and insert language-specific conditions in each template.
Ok thank you Nigel. Your shortcode does the trick.