Ecommerce Shopify WordPress Discussion

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.
I've found a simple solution that work like magic. As mentioned by @Ewout, check the box that says "Redirecto to cart page after succesful addtion". Woocommerce > Settings > Checkout (Tab) - where you should select pages for cart and checkout, select the checkout page as the cart page (image attached). That's it. works for me.

January 27, 2024

Update for WooCommerce 3.5.1 Step 1. First of all go to WooCommerce Products settings and deactivate AJAX add to cart. Step 2. Use woocommerce_add_to_cart_redirect hook to make a redirect to checkout. add_filter( 'woocommerce_add_to_cart_redirect', function( $url ) { return wc_get_checkout_url(); }); Of course there some small things are left to do, like changing add to cart buttons text and removing some WooCommerce cart-related notices. I recommend to check this tutorial for more https://rudrastyh.com/woocommerce/redirect-to-checkout-skip-cart.html

January 27, 2024

@RemiCorson posted this brief but beneficial tutorial: http://www.remicorson.com/woocommerce-skip-product-cart-pages/ He mentions the same filter as @Ewout above, 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; } but one line of code stands out and is of super value for me for my current woocommerce project: There is a direct link that a user can use to automatically bypass the product page. http://your-site.com/?add-to-cart=37 '37' will be replaced by your product ID. This was useful for me to eliminate unnecessary steps and take users directly to checkout from the home page and other non-woocommerce pages/posts.

January 27, 2024

Filter add_to_cart_redirect is deprecated in WooCommerce 2.6. Use woocommerce_add_to_cart_redirect instead. Add this to your functions.php : add_filter ('woocommerce_add_to_cart_redirect', function() { return WC()->cart->get_checkout_url(); } );

January 27, 2024

Try the below code in the themes function.php file add_filter( 'woocommerce_add_to_cart_redirect', 'woo_skip_cart_redirect_checkout' ); function woo_skip_cart_redirect_checkout( $url ) { return wc_get_checkout_url(); }

January 27, 2024

On shop page, if you want use ajax and redirect toghether. The second method only when there are some condition, you can use this filter and leave on Woocommerce setting ajax enabled: add_filter('woocommerce_loop_add_to_cart_link', array( $this, 'add_quantity_input' ), 4, 2); to remove on a class attribute ajax_add_to_cart and change the href value to checkout url page; On my template case: public function add_quantity_input($text = null, $product = null) { global $product, $woocommerce; if ( $text != null and $product != null ) { if(ismycondition($product->id)) { $s = explode('class="', $text); $s[2]=str_replace('ajax_add_to_cart', '', $s[2]); $text = implode('class="', $s); $text = preg_replace('/<a(.*)href="([^"]*)"(.*)>/','<a$1href="'.$woocommerce->cart->get_checkout_url().'"$3>', $text); } } return $text; } I hope that this help.

January 27, 2024

None of the solutions actually worked out for me, the filter add_to_cart_redirect was triggering on every page,not only on the cart.I did some modification on the suggested answer. add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { if(is_cart()){ $checkout_url = WC()->cart->get_checkout_url(); ?> <script> location = '<?=$checkout_url?>'; </script> <?php } }

January 27, 2024

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

January 27, 2024

There is an option within WooCommerce settings that allows you to enable this functionality: Simply login to your WP admin panel > WooCommerce > Catalog and select the option. I hope this helps!

January 27, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.