I
I
IgFil2020-11-20 11:23:58
WordPress
IgFil, 2020-11-20 11:23:58

How to get array of products in woocommerce cart?

I need to get an array of products in a woocommerce cart then get the price of products from a specific brand. Depending on the sum of the prices of these goods, make a discount on the goods of this brand.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2020-11-20
@IgFil

I think you are confusing the terms a bit. Products are products. This is what is displayed in the store catalog. And in the cart - this is order_item.

// Получить объект корзины WC_Cart:
WC()->cart;

// Получить массив WC_Order_Item в корзине:
WC()->cart->get_cart_contents()

Print out WC_Order_Item and see what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question