Skip to main content
Login Join
Snippet · PHP

Redirect to Checkout After Add to Cart

Shared by Shail Mehta · May 23, 2026

18 views
Back to Snippets

This code is used in WooCommerce to automatically redirect users to the checkout page immediately after they add a product to the cart.

add_filter( 'woocommerce_add_to_cart_redirect', 'sm_add_to_cart_checkout_redirect' );

function sm_add_to_cart_checkout_redirect() {
   return wc_get_checkout_url();
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments