Facebook Pixel

How to replace WooCommerce add to cart button with form link with extension

How to replace WooCommerce add to cart button with form link with extension
We provide you with our WooCommerce extension (WordPress) available on our GitLab. Indeed, the extension will allow you to decouple the functionality from your theme. For this, you will be able to change your design if you wish without having to redo the same maneuvers. Download and install on your website. It is however important to note that it is functional with the following conditions:
  • First, the extension only works on WordPress sites with WooCommerce installed.
  • Then you need to follow the steps below to finalize the setup
As good practice, we will recommend that you do some tests before putting it online. You can, for example, install on a local server or a test website.

How to replace the button using an extension

There are several extensions for WooCommerce that allow you to replace the add to cart button with a link to a form. I will walk you through how to do it with "YITH WooCommerce Request a Quote" extension.
  1. First, install and activate the "YITH WooCommerce Request a Quote" extension from your WordPress dashboard.
  2. Go to "WooCommerce" > "Request a Quote" > "General Options" to configure the extension settings as needed.
  3. In the "Product settings" tab, you can choose how the quote request form should appear on the product pages. For example, you can choose to display the form on all product pages or only on certain product categories.
  4. In the "Messages" tab, you can customize the messages that will display when a customer submits a quote request form.
  5. To replace the add to cart button with a link to the quote request form, go to "WooCommerce" > "Request a Quote" > "Button Replacement Options".
  6. Enable the "Replace Add to Cart Button" option and select the type of link you want to display. You can choose to display a text link, a button or an icon.
  7. Customize the link or button text if needed.
  8. Click "Save Changes" to save your settings.
Now the add to cart button on your WooCommerce product pages will be replaced with a link to the quote request form. Customers will be able to use this form to submit a quote request for the product rather than adding it directly to the cart.

To do it yourself, here are the steps

In this code, the replace_add_to_cart_button_with_form function retrieves the product ID and creates a link to the custom order form by adding an ID to the product URL. Next, she replaces the "Add to Cart" button with a link to the custom form. You will then need to create the custom form and place it at the location of the ID you added to the URL. For example, if the identifier is #custom-order-form , you can place the form where you want it to appear on the page by using that identifier in your HTML code.