3
votes

I'm trying to set "Add-to-cart" and "Buy Now" buttons in my product page:

  • Add-to-cart button: Simply add product in cart
  • Buy Now button:Add-to-cart and redirect to checkout page

I've tried this solution found on blogs:

 function dj_redirect_checkout( $url ) {
        global $woocommerce;
        $checkout_url = $woocommerce->cart->get_checkout_url();
        return $checkout_url;
    }
add_filter( 'add_to_cart_redirect', 'dj_redirect_checkout' );

After adding the above code, add-to-cart also redirects link to checkout page. How to accomplish this for both buttons in the product page?

2
i'm add another one copy of add-to-cart button for buynow button ,both functionality are same, but i'm trying to add onclick page redirect to chechout when user click buy now button plesase someone help to solve this problemraju

2 Answers

4
votes

Finally find a plugin to add buy now button to my product page, it work fine for simple and variable product page

link for plugin page

3
votes

Please try the following code:

function woo_redirect_to_checkout() {
 global $woocommerce;
 if($_POST['byenowpro'] == 'byenow'){
$checkout_url = $woocommerce->cart->get_checkout_url();
    return $checkout_url;
  }
}
add_filter ('add_to_cart_redirect', 'woo_redirect_to_checkout');

HTML example:

<input type="hidden" id="byenowpro" name="byenowpro" value="" />
<input type="submit" class="single_add_to_cart_button button secondary" id="byenow" name="byenow" value="Bye Now" onclick="byenowbutton" />