Skip to content

Redirect Add to Cart Only on Single Product Pages

I recently had a customer in chat who had an interesting request. They wanted the “add-to-cart” buttons on single product pages to redirect the user to the cart. They wanted the other “add-to-cart” buttons to leave the user on the current page.

It turns out we can do this with a simple filter. Add this to the theme’s functions.php file or use the Code Snippets plugin.

function ijab_redirect_single_add_to_cart() {
	return '/cart/';
}
add_filter( 'woocommerce_add_to_cart_form_action', 'ijab_redirect_single_add_to_cart' );

That should redirect simple and variable products to the cart when added from the single product page but leave product archives alone. I’m just posting it in case it helps someone out.

Leave a Reply

%d bloggers like this: