2

Woocommerce が行うことは...

製品が個別に販売されている場合、および製品がすでにカートに存在し、顧客が [カートに追加] をクリックすると、Woocommerce はエラー メッセージ "You cannot add another to your cart.....View Cart" を表示します。

上記のフローの代わりに、私が欲しい..

顧客が [カートに追加] をクリックすると、商品が既にカートに入っている場合、woocommerce はすぐにチェックアウト ページにリダイレクトする必要があります。

これは、Woocommerce Plugin の class-wc-cart.php のコードを数行編集することで実現できると思います。

を以下に示します。

// Force quantity to 1 if sold individually and check for existing item in cart
                if ( $product_data->is_sold_individually() ) {
                    $quantity         = apply_filters( 'woocommerce_add_to_cart_sold_individually_quantity', 1, $quantity, $product_id, $variation_id, $cart_item_data );
                    $in_cart_quantity = $cart_item_key ? $this->cart_contents[ $cart_item_key ]['quantity'] : 0;

                    if ( $in_cart_quantity > 0 ) {
                        throw new Exception( sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', wc_get_cart_url(), __( 'View Cart', 'woocommerce' ), sprintf( __( 'You cannot add another &quot;%s&quot; to your cart.', 'woocommerce' ), $product_data->get_title() ) ) );
                    }
                }
4

2 に答える 2