Support » Plugin: WooCommerce » How can I add Buy Now and Add to Cart Buttons to my Woocommerce Store

  • Hello friends,
    Please I am new to woocommerce. Can anyone tell me how I can add Buy Now button and Add to Cart button just like the one in aliexpress.com.

    With this features

    1. Here when a customer click on the Buy Now button, he will be redirected to checkout page with the product variations, bundle and options where different payment options are displayed without the product adding to cart. Also when he click on the ajax Add to Cart button the product will be added to cart with the product variations, bundle and options.

    2. and also display this Buy Now button to single products in the shooping cart page.

    Please Help me

    https://wordpress.org/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Allon Sacks

    (@allonsacksgmailcom)

    After much searching I was surprised this is not something that is standard.
    Here was my solution but mind you I did not test it for variations only for a normal product plus quantity in the single product page, so it might not work for variations though probably the same logic as in the js below would work for that:

    Either use a hook like “woocommerce_single_product_summary”

    Or copy the wp-content/plugins/woocommerce/templates/single-product/add-to-cart/simple.php to your child theme like:
    wp-content/themes/child-theme/woocommerce/single-product/add-to-cart/simple.php

    Edit the file and add the following code where you want the button to appear:

    <div class="express-checkout-wrapper">
                    <a id="dc_express_checkout" href="/checkout/?add-to-cart=<?php echo get_the_ID(); ?>">
                        Purchase
                    </a>
                </div>

    Now the only problem is the button will take you to checkout and add the correct product but without the correct quantity if you changed it so I used js in my custom.js file that is queued in the footer:

    // Add and change quantity to express checkout button when the quantity is updated
        if($('.cart .qty').length){
            var originalUrl = $('#dc_express_checkout').attr('href');
            $('.cart .qty').change(function(){
                var url = originalUrl + '&quantity=' + $(this).val();
                $('#dc_express_checkout').attr('href', url);
            });
        }

    You can change the url from:

    href="/checkout/?add-to-cart=<?php echo get_the_ID(); ?>"

    to:

    href="/cart/?add-to-cart=<?php echo get_the_ID(); ?>"

    If you want the button to direct to the cart instead of the checkout page.

    • This reply was modified 10 months, 3 weeks ago by  Allon Sacks.
    • This reply was modified 10 months, 3 weeks ago by  Allon Sacks.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How can I add Buy Now and Add to Cart Buttons to my Woocommerce Store’ is closed to new replies.