woocommerce : non available zero products

The woommerce defaut behaviour for products where price is not set is to disable the add to cart button  : my customer wanted this behaviour for product that have zero mentionned. Default woocommerce makes zeo product free!, but we decided to disable shopping cart for those too. very simple thanks to filters and template system:

 

  • in your functions .php , add

     

  • then create in your theme te following files 
    • /woocommerce/single-product/add-to-cart/simple.php
    • /woocommerce/loop/add-to-cart.php
    • and modify the first conditionnal test to make woocommerce display "not available" if price is zero : 

       

wordpress search by attachment title

Funny enough, there many search enhancement plugins for wordpress, but It seems none of them can do what I want : return posts if one its child attachments matches the search query. It's easy enough when you think about it but the code below will save you the hour I spent looking for it on google .