Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce add to cart button redirect to checkout

I created an ecommerce using the plugin woocommerce. I am selling only a subscription so the "/cart/" page is useless. I'm trying to get rid of it so that when my customer click on "Add to cart" button, he ends up on the checkout page.

like image 205
Michael Villeneuve Avatar asked Mar 23 '13 22:03

Michael Villeneuve


People also ask

How do I skip the WooCommerce Cart page and redirect to the checkout page?

You can skip cart definitively, redirecting customers to checkout page when cart url is called. To achieve this use this code snippet, that should do the trick: // Function that skip cart redirecting to checkout function skip_cart_page_redirection_to_checkout() { // If is cart page, redirect checkout.

How do I trigger add to cart button in WooCommerce?

Yes, that can be done by selecting the Redirect user to a URL option in your form's Behavior > Submission Behavior settings. Change yoursite. tld to your actual site, and change 7283 to the ID of the product you want added to the user's cart.


2 Answers

In WooCommerce 3.6 or later you can use woocommerce_add_to_cart_redirect (props @roman)

add_filter ('woocommerce_add_to_cart_redirect', function( $url, $adding_to_cart ) {     return wc_get_checkout_url(); }, 10, 2 );  

Original answer:

you can use a filter in functions.php:

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

it doesn't seem to work with ajax, but it works from the single product pages, which I think is what you use

On WooCommerce (>= 2.1) the function can be simplified as:

function redirect_to_checkout() {     return WC()->cart->get_checkout_url(); } 
like image 57
Ewout Avatar answered Sep 24 '22 15:09

Ewout


There is an option within WooCommerce settings that allows you to enable this functionality:

Option to redirect visitor to cart page

Simply login to your WP admin panel > WooCommerce > Catalog and select the option. I hope this helps!

like image 30
Devin Walker Avatar answered Sep 22 '22 15:09

Devin Walker