Answer the question
In order to leave comments, you need to log in
WordPress. WooCommerce. Displaying the number of items in the cart?
Hello.
I add a non-integer amount of goods to the cart and the cart displays "0 items". For example, product1 0.2 kg, product2 0.3 kg. Shows "0 items" in cart. How to make that showed "2 products"? Please tell me in which files to look for the required php code so that it counts the number of positions, and not the number of goods.
Answer the question
In order to leave comments, you need to log in
The product cannot be a whole, it is an essence. I don't quite understand how and why you did this. For the same product but different weight, use variations
There was a similar task, the number of unique products in the cart can be calculated like this: count( WC()->cart->get_cart() );
In the storefront theme, the number of products is displayed in the mini cart in the header, the code is in the storefront_cart_link function in the storefront-woocommerce-functions.php file
Look for where the number is displayed in the template -in the items in the cart through WC()->cart->get_cart_contents_count
and replace withcount( WC()->cart->get_cart() )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question