I’m looking for a way to add a custom button next to the add to cart button, but whereby I can enter the button link url into a product custom meta field.
I’ve created a new WordPress custom field for the certain woocommerce product pages I want to have a nearby custom url button on:
Custom field name: nothanks_link_redirect
Custom field value: https://yourcustomlink.com
UPDATE: I’ve found a suitable solution:
Tweak as you need and put this in your child theme’s functions.php :
/** WooCommerce custom field - 'No Thanks' Button **/
function nothanks_redirect_button() {
global $post;
$product_id = $post->ID;
$NoThanksLinkRedirectValue = get_post_meta($product_id,'nothanks_link_redirect',true);
if(!$NoThanksLinkRedirectValue) return;
echo '<a class="nothanks-button" style="margin-left: 20px" href="'.$NoThanksLinkRedirectValue.'" target="_self">No Thanks</a>';
}
add_action('woocommerce_after_add_to_cart_button','nothanks_redirect_button');
2
Answers
Enjoy
plz try below code in functions.php file