Forum

Thread tagged as: Shop

Shop cart get product slug

On the shop cart page I am trying to pass the product slugs into a variable but they are not accessible via perch_shop_cart(['skip-template'=>true]); I want to be able to pass these into perch_shop_product(); so that I can get optional product data output on the cart page. How can I achieve this?

Rob Saunders

Rob Saunders 0 points

  • 3 years ago

Did you try <perch:shop id="productSlug"> ?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Rob,

Since they don't seem to be accessible when skipping the template, you can return them (comma separated) in a template:

<perch:cartitems><perch:cartitem id="productSlug" /><perch:if not-exists="perch_item_last">,</perch:if></perch:cartitems>

And on your page:

// get the slugs from the template (returned as slug1,slug2,slug3)
$cart_product_slugs = perch_shop_cart([
    'template' => 'cart/slugs'
], true);


// filter by the slugs you collect above
perch_shop_products([
    'filter' => 'productSlug',
    'match' => 'in',
    'value' => $cart_product_slugs,
]);

Awesome thanks Hussein