skip to Main Content

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


  1. Chosen as BEST ANSWER

    Using the expand function (as suggested by karbi), I can now get the metadata that I added as follows:

    $checkout_lineitems->data[0]->price->product->metadata->mycustomfield
    

    The following links explain expanding objects in more detail with Stripe:


  2. 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:

    $checkout_lineitems = $stripe->checkout->sessions->allLineItems(
    $_GET['session_id'], ['expand' => ['data.price.product']] );
    

    After making that change, you should be able to access the product description.

    $checkout_lineitems->data[0]->price->product->description;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search