Add Quick Checkout Button Product Page WooCommerce – Redirect to Checkout Without Plugin

Categories:

Adding Quick Checkout function to your WordPress shopping website on product page it will redirect customer directly to payment checkout page without using any plugin.

Here we share a simple code that can help to fast your checkout process most of out theme already have this feature included you can enable or disable from settings.

Add Quick Checkout Button Product Page WooCommerce  - Redirect to Checkout Without Plugin

Before we start suggest you to take backup of theme in any situation you can restore is to default.

Add Quick Checkout button to Product page

First you need to open function.php file from Dashboard > Appearance > Theme Editor now choose file from right side of list.

You can also access file from FTP client then go to WordPress install directory > wp-content > YOUR_THEME > function.php

Now paste below code into theme file.

function insertcart_addtocart_button_func() {
// echo content.
global $product;
$pid = $product->get_id();
$quicklink = WC()->cart->get_checkout_url();
echo '<div class="button quickcheckout"><a href="'.$quicklink.'?add-to-cart='.$pid.'">'.esc_attr('Quick Checkout').'</a></div>';
}
add_action( 'woocommerce_after_add_to_cart_button', 'insertcart_addtocart_button_func' );

Above code will show Quick checkout button just after Add to cart button.

Additionally you can add css to button as well.


.button.quickcheckout {
    border-radius: 5px;
    clear: both;
    margin-top: 10px;
    padding: 8px;
    background: #339ad5;
}

Comments

2 responses to “Add Quick Checkout Button Product Page WooCommerce – Redirect to Checkout Without Plugin”

  1. Bruno Avatar
    Bruno

    Hi thanks a lot, this has been the only solution working for me. All the plugin redirects are broken.
    Although , i cant seem use variable products, i get the error : PLEASE CHOOSE PRODUCT OPTIONSโ€ฆ
    Is there any fix? Thanks in advance

    1. Sandy Avatar

      I don’t thing that above code with work on variable product because it grab product ID and take you to checkout page.For variable product you need diff. ID that means many quick checkout button as I understand for now.

Leave a Reply

Your email address will not be published. Required fields are marked *