Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
Created June 22, 2021 10:36
Show Gist options
  • Save tdmrhn/b7ebc341b0d1f1ad4299756e7edbaea7 to your computer and use it in GitHub Desktop.
Save tdmrhn/b7ebc341b0d1f1ad4299756e7edbaea7 to your computer and use it in GitHub Desktop.
Blocksy Add Buy Now Button After Add to cart
<?php
function add_buynow_button_after_addtocart() {
$current_product_id = get_the_ID();
$product = wc_get_product( $current_product_id );
$checkout_url = WC()->cart->get_checkout_url();
if( $product->is_type( 'simple' ) ){
echo '<a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'" class="ct-button">Buy Now</a>';
}
}
add_action( 'woocommerce_after_add_to_cart_button', 'add_buynow_button_after_addtocart', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment