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
     add_filter("woocommerce_free_price_html", "po_free");
     function po_free($price)
        return '' ;


  • 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 : 
      if(( $product->get_price() === ''   || $product->get_price()==0 )&& $product->product_type != 'external' ) {echo "<b>NON DISPONIBLE</b>" ;return;}


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *