Answer the question
In order to leave comments, you need to log in
How to show categories in Woocommerce cart?
In the basket, it is very necessary to make the division of goods into categories. There is an option here <?php echo $_product->get_categories(); ?>. But the problem is that in the basket the categories are displayed before each product:
Category 1
product 1 - 100 rubles.
Category 1
product 2 - 100 rubles.
Category 2
product 1 - 100 rubles.
Category 2
product 2 - 100 rubles.
And you need the output to be before a group of goods of a certain category:
Category 1
product 1 - 100 rubles.
item 2 - 100 rubles.
Category 2
product 1 - 100 rubles.
item 2 - 100 rubles.
Tell me how to do it better? Thanks in advance!
Answer the question
In order to leave comments, you need to log in
You can take the file from plugins/woocommerce/templates/cart/cart.php and copy it to your theme in the woocommerce/ folder. Inside the file, a table is displayed with the goods in the basket in a row, you can try to pass it so that instead of a cycle through all the goods in the basket, there is a cycle also by categories and display a separator like the title of the next category between categories. Accordingly, you need to get all categories and then filter products by them in the foreach loop ( WC()->cart->get_cart() as $cart_item_key => $cart_item )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question