Forum

Thread tagged as: Question, Shop

Cart Category

Hi All

Im using this

$category = perch_shop_cart([
    'skip-template'=> true,
    'return-html'=> false,
    'raw' => true,
],true);
print_r($category);

to get a array of the cart contents

but i cant see the product category in there

how can i get the category to display in the array

Thanks

Ant

Anthony Elleray

Anthony Elleray 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the objective? Are you trying to get the categories of all the products in the cart?

Yes

I'm then using it to pass a variable into a template

Which will then display diffrent cart_properties depending on the items in the cart

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right - the cart doesn't carry the full set of information about the products, just a reference to them. The cart has it's own problems to deal with :)

Do you see the product slugs or IDs in there?

Yes

At the moment I have used the SKU as part of the category is in the SKU

HCKAYA001

I then removed the first 2 and last 3 letters

And use that

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, if you have the product IDs, you'll need to then look up each product in turn to get the categories (using perch_shop_product())

There's not a more straightforward way, but it should be perfectly possible.

Ahhh I see

Thanks