• Resolved hormiganegra

    (@hormiganegra)


    Hello,

    I use this plugin to display woocommerce products.

    I have a loop that returns variable products and a nested loop that returns the product’s variations that have stock >0.

    My problem is that if the product has no variation with stock > 0 the product still is returned. I don’t know how to make the first loop evaluate if there is any child variation with stock >0 so that then and only then the product info is displayed.

    Is this possible using this plugin? Can you offer any guidance?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Maybe it’s possible with a CSS trick. For example: add a class “empty” if there are no results in the “single-product-wrapper”.

    Something like this? I didn’t test it and off course you have to put the “stock >0 condition” to the sub loop.

    <div class="all-products-wrapper">
    
     [loop type=product orderby=_sku]
    
     <div class="single-product-wrapper[-loop type=product_variation parent=this][if empty] empty[/if][/-loop]">
    
      [-loop type=product_variation parent=this]
      [field link] - € [field _price]
      [/-loop]
    
     </div>
    
     [/loop]
    
    </div>

    And the CSS:
    .empty { display: none; }

    Good luck!

    • This reply was modified 6 years, 11 months ago by Peter Berger.
    Thread Starter hormiganegra

    (@hormiganegra)

    Thanks for the inspiration. Took a bit, and not what I actually wanted but the end result was more than just adequate. Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Apply condition to parent loop’ is closed to new replies.