Hide recommendations blocks when they are no products in the recommendations
We use multiply recommendation blocks on the Page. They all work pretty fine. But there is one issue where i don't know how i can fix it and make it better.
For Example, we have multiple recommendation lines on the Page.
1.) You could also like this
2.) Customers also bought
3.) Recently viewed
4.) More of this brand.
Now my issue is that, when I have a Product where there are not so many Products of one brand. The Block 4.) Will be empty and not show any Product. How can I hide the whole block? Does anybody have a function where i can hide the whole block if the block can not be filled with Reco's?
-
Hey Manuel,
In order, to achieve action - hide recommendations widget, when there are no products in it, You can use a javascript function, which checks product count in the widget and if it's 0, then hide recommendations element.
To do so, after checking Your link, I can suggest you a function like this.
function hideEmptyRecommendations() {var rootNode = document.getElementById('dy-recommendations-${dyVariationId}');// Wait for product wrapper element, which holds a product elementsDYO.waitForElementAsync('#dy-recommendations-${dyVariationId} .dy-recommendations__slider-wrapper').then(function(elements) {// Check if, there are 0 products inside product wrapper elementif (elements[0].childElementCount === 0) {// If so, we set display to none for root element, which means, widget will be hidden.rootNode.style.setProperty('display', 'none');}});}After You place this function inside Your recommendations Javascript tab, make sure You also call it, using - hideRecommendationsIfEmpty();
Please sign in to leave a comment.
Comments
3 comments