How to Hide WooCommerce Product If Price Is Zero?????

Wanna to Hide Products, When Price is Zero ?
When you want to give product as freebies for your customers, like on Christmas and you don’t want to spend money for the customer freebies or you might be a developer then this solution is for you???.
If you left the price empty then,Woocommerce will disable the add to cart button.Beside that ,you dont wanna display price product rather you wanna hide the price and replace with message like ”This Product is free”.
- Go to Dashboard -> Appearance -> Editor
- Click on functions.php
- Add the following Code in the end of the functions file
add_action( 'woocommerce_product_query', 'hide_zero_price_product' );
function hide_zero_price_product( $q ){
$meta_query = $q->get( 'meta_query' );
$meta_query[] = array(
'key' => '_price',
'value' => 0,
'compare' => '>'
);
$q->set( 'meta_query', $meta_query );
}
Leave a Reply
You must be logged in to post a comment.