Answer the question
In order to leave comments, you need to log in
WooCommerce: How to add a "Buy Now" button in addition to the "Add to Cart" button?
Hello dear experts!
There was a task to add a "Buy Now" button to the product page for a quick transition to the payment page in addition to the "Add to Cart" button. After a long googling, I found only a couple of materials where it is proposed to remake the "Add to Cart" button into "Buy Now".
Any solution will do: a plugin or a function.
Answer the question
In order to leave comments, you need to log in
Here is the code to redirect all "Add to Cart" buttons to the checkout page. Unfortunately, it does not work with ajax-based buttons (they can be disabled in Woocommerce --> Settings --> Catalog --> Enable AJAX add to cart buttons on archives):
add_filter( 'add_to_cart_redirect', 'add_to_cart_redirect_to_checkout');
function add_to_cart_redirect_to_checkout() {
global $woocommerce;
return $woocommerce->cart->get_checkout_url();
}
<input type="submit" name="buy_now" ..... />
add_action('init', 'add_to_cart_redirect');
function add_to_cart_redirect() {
if ( isset($_GET['buy_now']) && .... || isset($_POST['buy_now'] ) {
// тут добавление в корзину и тд
// .....
// .....
wp_safe_redirect( $woocommerce->cart->get_cart_url() );
exit;
}
}
You click “buy now” and you immediately get into the basket, where, say, one product lies? If yes, then you can copy the functionality of the “add to cart” button and form links so that when you click it, you immediately go to payment, for example.
@sergeyrudnev it's not so simple there. The button code does not contain a link in its pure form.
Make it using a contact form in the PopUp window
You can use 2 plugins: form-lightbox and contact-form-7
Insert the shortcode from contact-form-7 into form-lightbox, and insert the shortcode generated by form-lightbox into the place where you want to see the button - buy now. The shortcode in PHP is inserted via <?php echo do_shortcode('SHOTCODE'); ?>
If the code is on the product page, then you can also pull out the URL of the product so that you can see which product is being ordered.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question