T
T
TopdiR2014-01-05 13:57:27
WordPress
TopdiR, 2014-01-05 13:57:27

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

5 answer(s)
M
mirusck, 2014-01-06
@mirusck

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();
}

This is so, offhand. I'll think at my leisure how to make two buttons in parallel. So far, I see an option like this:
1. Add custom buttons in all templates
2. Depending on which page: catalog or one product, the buttons should be either urls ( example.com/?add-to-cart=486&buy_now ), or submit with buttons <input type="submit" name="buy_now" ..... />
3. Custom $_POST and $_GET handler, which manually, using classes like WC_Cart, WC_Product, etc., adds the product to the cart and redirects to checkout
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;
    }
}

Here, again, the processing of Ajax requests will be controversial, for which it will be necessary to add a separate handler.

S
Sergey Rudnev, 2014-01-05
@sergeyrudnev

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.

T
TopdiR, 2014-01-06
@TopdiR

@sergeyrudnev it's not so simple there. The button code does not contain a link in its pure form.

M
Macsimus, 2014-03-18
@Macsimus

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.

K
Kirill Atstarov, 2017-06-30
@malkiel

try the "Buy one click WooCommerce" plugin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question