I am using the Enterprise theme and currently have a featured collection section for our sale items. However, if we do not have any items on sale I would like to hide this section. I have added a ‘custom HTML/liquid’ section with the below code.
You need to loop over the products and check whatever the logic is that use to call a product “on sale”
{% assign has_product_on_sale = false %}
{% for product in collection %}
{% if product.price < product.compare_at_price %}
{% assign has_product_on_sale = true %}
{% endif %}
{% endfor %}
{% if has_product_on_sale %}
#shopify-section-template--25939786662173__featured_collection_pVELqV {display: none;}
{% endif %}
Before reaching for that band-aid and living with it forever fix the real issues upstream first:
If the section displays even when a collection is empty contact the theme developers and make that feature request; it really is annoying how many things work like this in themes.
make the collection conditions be empty when there’s no sale products either by tags or pricess etc;
And or using an automation app like flow or mechanic to control tags
or make a it a manual collection populated by such a custom automations logic
Alternative:
If you have time to waste or need to get hands on with some sort of “AI” for the experience there’s also asking the sidekick tool to try and randomly generate a section:block with the wanted requirements and more.
This can be good testing/training to get used to such a workflow for one-offs or making prototypes even if they don’t fully work before bringing in experts. https://help.shopify.com/en/manual/online-store/themes/customizing-themes/theme-editor/shopify-magic/generate-blocks
Thank you for your response. It’s good to know that it’s worked for you. Kindly feel free to get back to me if you need any further assistance. If helpful, please like all posts.