WooCommerce: Change Add To Cart Button Text and URL

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.

replace woocommerce add to cart button
Replaced Add To Cart button with a custom button title and url
woocommerce add to cart button custom url with parameters
Button click redirects to a custom url with product parameters

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.

Was this article helpful?

Keep In Touch


Wil is a dad, WordPress consultant, WordPress developer, business coach and mentor. He co-organizes the WordPress Sydney meetup group and has been on the organising committee for WordCamp Sydney since 2014. He speaks at many special events and contributes to the WordPress open source project. His likes are chillies, craft beer and electrogravitics.