I'd like to add a button next to "Add to Cart" on the product page that adds "-sample" to the product URL when clicked.
Example:
You're viewing Product 1's page and the URL is "http://www.example.com/shop/product-1/
"
When you click on the button, it adds "-sample" to the URL
"http://www.example.com/shop/product-1-sample/
"
How can I achieve this?
Thanks
For woocommerce 3+ (only):
In woocommerce 3 you will use
woocommerce_after_shop_loop_item
action hook instead, as the hookwoocommerce_after_add_to_cart_button
will not work anymore.Code goes on
function.php
file of your active child theme (or active theme). Tested and works.Before woocommerce 3:
This is possible using hook
woocommerce_after_add_to_cart_button
to add your additional button on product pages, using this custom function:This code goes on
function.php
file of your active child theme or theme.This code is tested and fully functional.
Based on this: Add a button after add to cart and redirect it to some custom link in WooCommerce
And this: PHP - How to remove all specific characters at the end of a string?