Archived topic
button
1 reply · Started by Den on February 1, 2022
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 :(
Hi there,
that code only adds the button if it is a Simple Product.
It won't work on Variable Products, the only method i know for doing this is to use the official extension:
https://woocommerce.com/products/quick-buy-now-button-for-woocommerce/