Redirect Duplicate Cart Additions
-
If a customer has 1 of some item in their cart, and that item is ‘sold individually’, I want to redirect them to the cart instead of displaying the notice (“You cannot add another…”).
The following code does exactly that, however only when in the shop loop. I have created custom pages outside of the shop loop that make use of shortcode. How is it possible to adapt this for use with shortcode?
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; }
What currently happens when clicking the shortcode with the product already in the cart is that the button gets stuck in a ‘loading’ state. The only thing I’m able to do is take advantage of the loading state by writing some CSS rules that suggest the item is already in the cart, but that’s a really rough way around it.
- The topic ‘Redirect Duplicate Cart Additions’ is closed to new replies.