Well this was a pain to find. In fact, I didn’t even find it, I ended up hacking a bunch of code together in order to figure it out. But the good new, I did figure it out, and now I want to share it with you! So anyone who’s been trying to change the text to the add to cart link for simple products on WooCommerce, I got you. If you’re trying to change the LINK to the add to cart link so that it goes to the product page, I got you again!
Let’s start with the resource. After scouring the internet and twitter to try and find an answer, I came across this cool little website. It had a couple of snippets that seemed legit, but the only problem is that they didn’t work on the latest release of WooCommerce.
Fast forward, I also found this cool snippet of code (can’t remember where) that allows you to change the text of the WooCommerce buttons by the type of product!
[gist id=”c1b3db44d0cd761b14f1″ file=”woo-text-change.php”]
Now pay attention to the function. You can keep the filter there if ALL you want to do is change the text that displays. But if you want the link, all you need is the function.
The second step is to now change the link. I did this by copying and pasting the original HTML for the
a tag. This way all the classes, etc., are kept in tact. Then I added the appropriate php variables.
[gist id=”c1b3db44d0cd761b14f1″ file=”woo-change-addtocart-link.php”]
And that’s it! Now you can control the link AND the text! In fact, you have full control over the link so you can make it a button, a form, whatever you want, it’s there! Keep the text-change function, and you’ll be able to change the text for any type of product you have.
Hope you enjoy!