L
L
ligisayan2016-03-17 13:29:54
Electronic commerce
ligisayan, 2016-03-17 13:29:54

What function counts products in the shopping cart on woocommerce?

Hello! There is a site on wordpress + woocommerce and there is a need to count the number of goods in the basket. Tell me pliz function what function or loop can be used for this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zhainar, 2016-03-17
@zhainar

see global variable $woocommerce

L
ligisayan, 2016-03-19
@ligisayan

And here is the answer:

/**
         * Get number of items in the cart.
         * @return int
         */
        public function get_cart_contents_count() {
            return apply_filters( 'woocommerce_cart_contents_count', array_sum( wp_list_pluck( $this->get_cart(), 'quantity' ) ) );
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question