Skip to main content

Relationships

The order model has some convenient ways to find loaded relationship data. These methods and properties do not perform queries, they simply make accessing nested data easier.

$order->prices​

You can each of the order->line_item->price using the prices property.

So instead of this:

$prices = array_map(function($item) {
return $item->price;
}, $order->line_items);

You can simply do this:

$prices = $order->prices;

$order->price_ids​

You can each of the order->line_item->price->id using the prices property.

$prices = array_map(function($item) {
return $item->price;
}, $order->line_items);
$price_ids = array_map(function($price) {
return $price->id;
}, $prices);

You can simply do this:

$prices = $order->price_ids;

$order->hasSubscriptions()​

Does the order contain a subscription?

$has_subscription = (bool) $order->hasSubscriptions();

$order->hasPriceId( $id (string) )​

Does the order have this price id in it's line items?

$has_subscription = (bool) $order->hasPriceId( '8ba8d60f-5277-4e6b-807c-dee8166446d5');