Site logo

Archived topic

button

1 reply · Started by Den on February 1, 2022

Viewing posts 1–2 of 2

Hello team,

I am trying to add a "Buy Now" button right next to the "Add To Cart" button. (on my WooCommerce website) without using any plugin.

This is the code I am using. I got this code from the comment section of a random Youtube video. But it doesn't work.

add_action('woocommerce_after_add_to_cart_button', 'buynowbutton');

function buynowbutton() {
	$product_id=get_the_ID();
	$product=wc_get_product($product_id);
	$checkout_url=wc_get_checkout_url();
	if($product->is_type('simple')){
		echo '<a href="'.$checkout_url.'?add_to_cart='.$product_id.'" class="quickbuy">BUY NOW</a>';
	}
}

Can you help me out :(

This archived topic is closed to new replies.