Replace the default WooCommerce Add To Cart button with a new button with custom text and URL link with product parameters.
The code snippet below will remove the existing WooCommerce Add To Cart button and replace it with a new button that you can change the button text and have a custom URL link when a customer clicks on it.
I’ve also added some WooCommerce URL parameters which can come in handy of you are redirecting to a contact form.
You can modify the style using CSS.
URL Product Parameters
The following product parameters area added to the custom URL
wc_id = the product ID
wc_price = the product display price without currenct symbol
wc_title = the product title
wc_product_link = the URL link to the product
Where To Put The Code Snippet?
This code snippet should go in your active theme’s functions.php file.
Add it to the bottom of the file, before any closing ?> characters.
It’s always a good idea to take a backup of your functions.php file in case anything goes wrong – you can just copy the old code back in again.