Created
December 12, 2018 11:35
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.