How do you access the line items metadata for each product when using php and alllineitems?
$checkout_lineitems = $stripe->checkout->sessions->allLineItems( $_GET['session_id'], [] );
There seems to be no clear documentation for this.
Also if I set the name and description for a product as follows:
'product_data' => ['name' => 'Item 1','description' => 'My item']
How do I retrieve the description? If I use the following line, it returns the name!
$checkout_lineitems->data[0]->description
Thank you.
2
Answers
Using the expand function (as suggested by karbi), I can now get the metadata that I added as follows:
The following links explain expanding objects in more detail with Stripe:
By default, retrieving a Checkout Session’s line items will give you back the full Price object, but just the Product ID (see api ref). If you want to get back the full product object you need to expand
data.price.product
like this:After making that change, you should be able to access the product description.