• Resolved albla

    (@albla)


    hi, I had to show the cart icon with the number of products on my menu for woocommerce BUT I did not want to have the aggregate number of items because of some of them are based on grams and some on units. I had 13 items and 1000 kilograms of one item and the total was 1013 items in my cart. So I used some code from the internet and I added the next code:

    $cart_contents = $woocommerce->cart->get_cart();
    $cart_product_contents_count = count($cart_contents);
    .
    .
    .
    $menu_item .= “{$cart_product_contents_count}” . ” – “. $cart_total;

    you can add it at your plugin as a choice
    best Alex

Viewing 1 replies (of 1 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @albla

    Try this method instead:

    add_filter('woocommerce_cart_contents_count',function($count){
    	return count(WC()->cart->get_cart());
    });

    If you never worked with filters please read our documentation page: How to use filters

Viewing 1 replies (of 1 total)
  • The topic ‘number of products’ is closed to new replies.