Alecu Marian Alexandru
Alecu Marian Alexandru

Reputation: 705

WooCommerce Always redirect to checkout even if product already exists in cart

How can I always redirect to WooCommerce checkout even if the product sold individually is already in cart?

I have my cart integrated in the checkout and WooCommerce will stay on the same page without going to checkout if that product is already in the cart.

Best, Marian Alexandru Alecu

P.S.

Upvotes: 1

Views: 880

Answers (1)

Alecu Marian Alexandru
Alecu Marian Alexandru

Reputation: 705

My fix was to hijack the add to cart flow of WooCommerce and redirect to checkout if the product already exists:

add_filter( 'woocommerce_add_to_cart_sold_individually_found_in_cart', 'bypass_add_to_cart_sold_individually_found_in_cart', 10, 2 );

function bypass_add_to_cart_sold_individually_found_in_cart( $found_in_cart, $product_id ) {
    if ( $found_in_cart ) {
        wp_redirect(wc_get_checkout_url());
        
        exit;
    }
    
    return $found_in_cart;
}

Upvotes: 3

Related Questions