Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce: Auto-redirect to cart after adding product from category

Tags:

http://www.passgotutoring.com/shop/product-category/ucla/ucla-14a/

I am trying to get a auto redirect towards WP_Cart to happen as soon as a client "adds to cart" one of our classes that are located on the left.

Most of my clients buy a product, pay for it right away so I dont need to really have them keep shopping or anything.

I have tried inputting this code in to my function.php of my theme with no luck when I wanted them to go to their checkout directly.

add_action('init','woocommerce_go_to_checkout_action',30); function woocommerce_go_to_checkout_action(){ if ( empty( $_REQUEST['add-to-cart'] ) || sizeof($woocommerce->cart->get_cart())==0) )     return; wp_safe_redirect( $woocommerce->cart->get_checkout_url() ); } 

Any ideas on how I could get it to work? 1. I would like it to go to cart instead of checkout. 2. I tried the checkbox method on the catalog page and it did not work.

like image 754
user1810236 Avatar asked Nov 08 '12 18:11

user1810236


People also ask

How do I redirect in WooCommerce?

The Redirection plugin allows you to create URL redirects for WordPress sites. Just enter the source (old) URL, the target (current) URL, and click “Add Redirection.” That's it — you're done.


1 Answers

In WooCommerce 3.x you'll find this setting under:

WooCommerce > Settings > Products > General > Add to cart behaviour > [✓] Redirect to the cart page after successful addition


In WooCommerce 2.3 you'll find this setting under:

WooCommerce > Settings > Products > Display > [✓] Redirect to the cart page after successful addition


In WooCommerce 2.1 you'll find this setting under:

WooCommerce > Settings > Products > [✓] Redirect to the cart page after successful addition

like image 67
Andrew Avatar answered Oct 05 '22 14:10

Andrew