Please try to add following code into your theme functions.php file
function remove_add_to_cart_option( $purchasable, $product ){
if( $product->get_price() == 0 )
$purchasable = false;
return $purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_option', 10, 2 );
Replace below function instead of above and check again
/*
* Override via functions.php
**/
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
function woocommerce_template_loop_add_to_cart() {
global $product;
if ( ! $product->is_in_stock() || ! $product->is_purchasable() ) return;
woocommerce_get_template('loop/add-to-cart.php');
}
}
Let me know if any query.
Hope it will help you !
Related Posts:
- How to get current product category ID in product archive page
- WooCommerce prices location in DB
- WP/WooCommerce REST API cart/checkout/order [closed]
- Fatal Error when installing woocommerce despite upgrading
- Adding an action within a function that is being called by add_filter
- Hide Add to Cart Button
- Pass custom Checkout field value to Stripe gateway in WooCommerce
- How to modify “[Product] has been added to your cart” in WooCommerce?
- woocommerce fail to replace template string in email title [closed]
- Why do Woocommerce templates use hooks rather than get_template_part
- Woocommerce checkout via external page [closed]
- Change font size in products listing pages in woocommerce
- How to stop a Gutenberg Block from firing multiple GET Requests?
- Trying to disable slider for WooCommerce price filter [closed]
- Hide “Delete Note” link in Order Notes Panel
- Woocommerce reviews xss issue [closed]
- Unable to update Woocommerce Product Permalink
- wp_customize – detect post type to show/hide customizer options
- How to select default Woocommerce category page
- Creating Product Table using Gutenberg
- I can ‘t display product images based on the label
- SKU for each product on every page
- Woocommerce get billing state manually
- WooCommerce quick checkout form? [closed]
- woocommerce cart item remove ajax not working in hosted site [closed]
- Set woocommerce product price based on dealer location [closed]
- How can I custom order the product display?
- WordPress plugin cloak link [closed]
- Woocommerce REST API – updating an order changes custom tax calculations
- Woocommerce Update Causing Internal Server Error [closed]
- remove default pagination on woocommerce shop page
- WordPress Comment Box on woocommerce product page [closed]
- Remove Bulk Action For non admin user
- Add max-value to hooked quantity selector in woocommerce [closed]
- Can’t remove woocommerce sidebar
- Woocommerce Slow Queries
- woo product , wp_insert_post() never displays on the front end. What gives? [closed]
- Single product page doesn’t display price
- Should I use docker in wordpress production?
- Unable to paste google analytics con header.php [closed]
- can’t get the product id in single woocommerce page
- Php echo woocommerce price
- Different files for order details
- Multiple Schema.org markups on a single product page
- Woocommerce – Adding row to cart table
- Hide a product with a certain tag from product-category
- WooCommerce get_author_posts_url() – Author URL redirecting to shop base
- Error message if user is buying less than 200 euros of a given product [closed]
- WooCommerce show a variation both in check boxes and in a list
- Woocommerce – How to mix products and posts on a landing page?
- Disable woocommerce product search plugin’s autocomplete [closed]
- Add sub variations in product page
- Woo commerce product quantity wise SKU
- Override une fonction dans une class Woocommerce
- What to do if images are not displayed in mob. versions of the online store on wordpress?
- WooCommerce (Bookings) + AddOns not always calculating correctly the total
- Woocommerce order proceed hooks
- How can i get the code of Shop Page Woocommerce?
- List of JS events in the WooCommerce frontend
- WooCommerce custom product type not saving with namespaces
- Add shortcode to show woocommerce shipping class name on product template
- Redirecting orders by company field
- Upload file to Woocommerce Order
- wp_login overriding user meta data
- pass a woocommerce product name to contact form7?
- woocommerce REST api on the website’s front-end
- Woocommerce List categories with Image thumbnail
- How to add (and change the font of) the short product description to order page and customer’s new order e-mail [closed]
- Display WOO Commerce products on HTML page?
- How to add custom text field inputs for attributes in backend?
- Get unsolved array keys of product data tabs in woo product editor page
- Show products as posts on archive page
- Woocommerce new shop page
- Add class to latest item Woocommerce
- How to customize product at cart page
- WooCommerce Storefront site-header padding
- WooCommerce: How can I add a certain product to the cart and redirect to the cart from a non-shop page?
- Make Woocommerce breadcrumbs show up using functions.php file
- Alter the cost of products using phpmyadmin sql query
- How does one allow any customer to process any order in store on woocommerce?
- How to check which shortcode is using my template?
- Update products with curl (bash)
- How to get woocommerce integration instance?
- Create woocommerce order on new user registration
- How to put a date range in a virtual/downloadable product? [closed]
- Woocommerce Child Category Permalink Structure Change
- Allow customer to choose an optional free/paid product to add to their order (and reduce stock reduced & record sale)
- Stop the “upload file size” error from printing [closed]
- Redirect whole website or pages to /wp-admin in wordpress
- Changing sale price programmatically, but it’s not shown on front-end
- How to disable the “Upgrade or Downgrade” button in “My account” of WooCommerce Subscriptions
- WooCommerce – Inconsistent Indexing of Orders
- How to remove slug from Product category URL in Woocommerce
- Removing ‘woocommerce-no-js’ class from body
- url rewrite doesn’t load woocommerce product
- Add Additional 3 buttons next to “Add to cart” button in woocommerce product page
- How do I remove the recurring total from thank you for your order email?
- Display product categories + child-categories on a single product page
- I want to Display custom woocomerce meta box in orders list
- Detect Product Type with code