My client has the pro version, and I see the Products Quantity Limit, but that only affects how many of a specific product you can add to your cart.
What I need, is for ex: I have a funnel with 5 unique products to select, I want to limit the users to only be able to select 2 out of the 5. And it shouldn’t let you select a 3rd product.
What I did for a workaround is to modify function viwcuf_us_woocommerce_add_to_cart_quantity for:
if ( isset( $_REQUEST['viwcuf_us_product_id'] ) ) {
$qty = isset($_REQUEST['quantity']) ? floatval(sanitize_text_field($_REQUEST['quantity'])): 1;
// Determine the total number of upsell products already in the cart
$current_upsell_products_in_cart = 0;
foreach ( WC()->cart->get_cart() as $cart_item ) {
if ( isset($cart_item['viwcuf_us_product']) ) {
$current_upsell_products_in_cart += $cart_item['quantity'];
}
}
// Check if adding the new products will exceed the limit of 2
if ($current_upsell_products_in_cart + $qty > 2) {
wc_add_notice( __( 'Solo puedes agregar un máximo de 2 productos.', 'woocommerce-checkout-upsell-funnel' ), 'error' );
return 0; // Do not add the product to the cart
}
return $qty; // Allow the product to be added to the cart
}
-
This reply was modified 1 year, 5 months ago by
stranyer.