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.
6 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
2try to uncheck this..
WooCommerce > Settings > General > Scripts > [✓] Enable AJAX add to cart buttons on product archives
1WooCommerce Settings | Catalog | Catalog options | Add to cart | Please check the "Add to cart Redirect to the cart page after successful addition" option.
In WooCommerce 2.1.8 you´ll find this setting under... WooCommerce Settings | Products | Enable AJAX add to cart buttons on archives
In WooCommerce 2.3.11 you'll find this setting under...
WooCommerce > Settings > Products > Display > Add to cart behaviour > [✓] Redirect to the cart page after successful addition
Using a filter hook, you can use the following snippet.
add_filter('woocommerce_add_to_cart_redirect', 'change_woocommerce_add_to_cart_redirect_url');
function change_woocommerce_add_to_cart_redirect_url($url){ $url = wc_get_cart_url(); return $url;
}The code goes into your child theme or active theme's functions.php file. Tested and working.