• Resolved fivemarcus

    (@fivemarcus)


    Hello,
    in the cart I would like to count only the number of different products inserted.

    If a user buys 3 quantities of the same product, I would like to see “1 product” written, by default it also counts duplicate products and therefore 3.

    In my case the quantities are the kilograms of product, for this reason I have this need

    How can I do?
    What exactly should I write in the function.php file?

    Thanks so much

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    Admittedly I’m not 100% sure of the use case here: Why would you like to count 3 quantities as 1?

    Perhaps it would help if you created a variable product where each variation is a predetermined Kilogram (e.g. 1 Kg, 2Kg, 5Kg, 10Kg etc.) –> Once the variation has been added to the cart, it’ll show up as 1 x 5Kg product) ??

    Thread Starter fivemarcus

    (@fivemarcus)

    – if I use variations, I can’t easily keep track of sales statistics:
    I will see that I have sold:
    10 times the 5kg tomatoes
    6 times the 1kg tomatoes

    Without variation I will see that I have sold.
    56 times the 1kg tomatoes
    so I sold 56 kg of tomatoes

    – With the variations I should foresee all the possibilities, which could be many, complicating both the product creation process and reducing the user’s UX.
    Now the user clicks on + and -, or enters the number of kgs from keyboards

    In detail the order is shown to the customer who is buying: 10 quantities of tomatoes.
    But in the preview on the cart, which shows the number of products in the cart, I would like to show only the number of different products.
    If a customer buys 10 quantities of tomatoes, I would like to show 1 and not 10.

    Thanks for your help and interest in the use case

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    But in the preview on the cart, which shows the number of products in the cart, I would like to show only the number of different products.
    If a customer buys 10 quantities of tomatoes, I would like to show 1 and not 10.

    If you wanted to just always show quantity of 1 for Cart items, you could use this PHP snippet:

    
    // Always display quantity = 1 for Cart items
    add_filter( 'woocommerce_cart_item_quantity', 'my_custom_cart_quantity' );
    function my_custom_cart_quantity( $quantity ) {
        $quantity = 1;
        return $quantity;
    }
    

    Alternatively, since that quantity would be essentially meaningless since it just displays 1 no matter what is in the cart, you could just hide that column in the Cart table with CSS:

    
    /* Hide quantity column in cart */
    .woocommerce-cart .product-quantity {
      display: none !important;
    }
    

    Finally, if you would like to add full functionality for managing your products in different units (kg, m, etc), you could check out the Measurement Price Calculator extension available here:
    https://woocommerce.com/products/measurement-price-calculator/

    I hope that helps! Have a wonderful day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘cart must count only different products, not quantities’ is closed to new replies.