When you Google the phrase “replace Add to Cart WooCommerce” (or any variants thereof), there are a lot of SERP’s suggesting the same way of hiding/not displaying the Add To Cart button. The idea is to remove the “woocommerce_template_single_add_to_cart” action.
Replace “Add to Cart” for Custom Products
However, in my case, I wanted to do this for only certain specific products. I have products that are marked as “Custom”, i.e. not stocked products. These are products that can be customized as per the customer/client. They usually take 6-8 weeks from order to delivery. The idea for the landing pages for these “Custom” products is not for them to make the purchase outright, but get them to contact the store owner. This way, the process of designing the custom product can be taken offline.
How to Designate a Product as “Custom”
The first step is to identify the products as “Custom” in WooCommerce. Following this guide by Remy Corson, I added a Checkbox under the General tab in the Product Edit Screen. When this Checkbox is checked, it means that the Product is “Custom”.
As you can see in the image above, this product is defined as “Custom”.
Next up, we have to hook into the correct action for marking all “Custom” products as not being allowed for Purchase. We will use the
is_purchaseable() hook for that purpose.
Alternative CTA for “Custom” Products
I wanted a form to take the place of the “Add To Cart” button. In my case, I use Contact Form 7 for my forms. I just added a small form specifically for the purpose of this CTA. The visitors will see this form in place of the Add to Cart button. The store owner receives an email containing the lead.
We are simply checking if the Product is “Custom”. If it is “Custom”, we will set it as being non-purchaseable. This will hide the “Add To Cart” button for such “Custom” products.
Full Code Listing
Here is the full code. Notice that 2 other custom fields were added. You do not need those, so you can easily delete the relevant lines of code.
Questions/Comments? Type away in the comments below.
Leave a Reply