i have two different categories for woocommerce products, when i'm on category A page there should be products in mini cart section from category A only.

and when on category B there should only be category b products in mini cart.

i have mini-cart.php and other is mini-cart-b.php

when i click "add to cart" it out puts perfect data against category only products, but when i click on category B LINK mini cart shows category A products :( and this is the problem. and if i click add to cart on category B page than it gets updated with products against this category.

what i want to understand is when page loads how data is populated in mini-cart which file is being used or data comes from session ?

if it comes from session how i can edit it on page redirect

this is how i'm showing different products for different categories

first creating index on WC()->cart->get_cart() object

foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

            $terms = wp_get_post_terms($cart_item['data']->id, 'product_cat' );
            $products_by_categories[$terms[0]->name][] = $cart_item;
            $cart_keys[$cart_item['product_id']] = $cart_item_key;

than looping through products_by_categories

foreach ( $products_by_categories as $cat_name => $cart_items ) {

listing products

foreach ( $cart_items as $tmp_index => $cart_item ) {

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.