Hide div in sidebar depending on number of WooCommerce products

1 answer

Is it possible to hide a div in the left sidebar depending on how many WooCommerce products are displayed?

Let's say the div in the sidebar is called 'last-img' and the number of products would have to be > 9 to display the div.

Received answer to this question:
The best answer according to the author of the question:

One way to do that would be using js, counting your elements using getElementsByClassName:

var numberOfElements = document.getElementsByClassName('products').length; 

Then :

if (numberOfElements > 9) { document.getElementById('last-img').style.display = 'block'; } else { document.getElementById('last-img').style.display = 'none'; }