Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created December 12, 2018 11:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillBrubaker/4b2798706d56f75d82997ddf29ab210f to your computer and use it in GitHub Desktop.
Save WillBrubaker/4b2798706d56f75d82997ddf29ab210f to your computer and use it in GitHub Desktop.
WooCommerce redirect to cart if trying to add a 'sold individually' item that is already in the cart
//not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
add_filter( 'woocommerce_add_to_cart_sold_individually_found_in_cart', 'handsome_bearded_guy_maybe_redirect_to_cart' );
function handsome_bearded_guy_maybe_redirect_to_cart( $found_in_cart ) {
if ( $found_in_cart ) {
wp_safe_redirect( wc_get_page_permalink( 'cart' ) );
exit;
}
return $found_in_cart;
}
@chiku012
Copy link

problem with this is if users hit the back button and retries to add the same product it doesn't goes to checkout page. instead goes to cart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment