D
D
DmitryShishov2018-02-12 15:25:12
WooCommerce
DmitryShishov, 2018-02-12 15:25:12

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

1 answer(s)
I
its2easyy, 2018-03-06
@its2easyy

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 question

Ask a Question

731 491 924 answers to any question