In a Single Product Page template, I would like to hide a section IF
the product has no cross-sells (meta key is “_crosssell_ids”), so if _crosssell_ids is empty, hide the section, however I am not being able to be successful with it.
I noticed that every default option available from the “Dynamic data” shows up between {curly brackets}, I tried placing {_crosssell_ids} but it still didn’t work.
How do you place a custom field / meta key in Bricks, kind of like how you did in oxygen?
I have already tried a few variations, even with the curly braces, even tried to select specifically equal to product IDs that are attributed as cross sales of the product, but no matter what I can’t get it to work.
Is it possible to use custom fields / metakeys with Bricks conditions or not? cause it seems like it only works with the available/default options from the dropdown.
@timmse Any chance you could provide some insight in this? Thank you so much in advance
I will try without “" ( * Between these quotes there is an underscore)
Until I know, this is a prefix to make the field private (This is why you don’t see it in the bricks list).
But I don’t know what is the real behaviour of the fields starting with "” (* Here too)
Hey Marco! Thank you so much for your feedback (and for doing a good job of clarifying what you meant ), I really appreciate it.
I gave a shot without the initial underscore but it seems like the result is the same.
Yeah supposedly from the documentation I found that is supposed to be the cross sale metakey
So far the way I have managed to do it is by using a code block and using custom code there which is working really well, I wished to have achieved it fully with Bricks but oh well.
The biggest problem I see with this is that here the code block element still displays in the DOM unecessarily, where as with Bricks Conditions I can get it to entirely hide the section.
<?php
global $product;
// Get the IDs of the cross-sell products for the current product
$cross_sell_ids = $product->get_cross_sell_ids();
// Output the section's content only if cross-sell products exist
if ( ! empty( $cross_sell_ids ) ) {
?>
<div class="my-section">
<!-- Your section content goes here -->
</div>
<?php
}
?>
Hey @jcmatoskx,
thanks for getting in touch.
Please try the cf_
prefix as described in the academy.
So in your case: {cf__crosssell_ids}
Best,
André
That’s it! Works perfectly! All I had to do was write the cf_ prefix
it’s quite simple but I had no idea about this as I would not assume that there would be such a specificity and I assumed that all meta keys should just be their own name.
I would just assume this is a bug / not possible with Bricks builder, but all it took was you sharing this knowledge of the documentation.
Thank you so so much André!
Thank you for following up on the solution, I was myself pulling out my hair! Works for upsells also