WoodMartW
WoodMart
May 29

Sold Individually Add to cart fix

All products in my store are sold individually. The issue is that when a customer adds something to cart but continues browsing, they then try to add the item to cart again in order to checkout but they get the default error message saying "You cannot add another to your cart". They get confused or impatient and they leave. I am losing A LOT of sales due to this issue. Could you please add a feature where if the product is already in the cart, the Add to Cart button now says something like: "Already Added: Click To Checkout". And when they click this add to cart button on a product that is already in the cart, the error message doesnt show, they are just taken to the cart to checkout without adding the item again. I got the following code, its working fine for the first part but then incorrectly tries to add the product to cart again on the second press instead of just going to cart: // Change button for single products add_filter('woocommerce_product_single_add_to_cart_text', 'already_in_cart_single_product'); function already_in_cart_single_product($label) { foreach (WC()->cart->get_cart() as $cart_item_key => $values) { $product = $values['data']; if (get_the_ID() == $product->get_id()) { $label = __('Already Added. Click to Checkout', 'woocommerce'); } } return $label; } // Change button for archive page products add_filter('woocommerce_product_add_to_cart_text', 'already_in_cart_archive_product', 99, 2); function already_in_cart_archive_product($label, $product) { if ($product->get_type() == 'simple' && $product->is_purchasable() && $product->is_in_stock()) { foreach (WC()->cart->get_cart() as $cart_item_key => $values) { $_product = $values['data']; if (get_the_ID() == $_product->get_id()) { $label = __('Product already in Cart. Add again?', 'woocommerce'); } } } return $label; }
PendingPending