I want to write a plugin which writes all the order data into a CSV file. Unfortunately the documentation for Commerce 2 isn't quite complete yet so I have difficulties to find out how to do the following with a plugin (so I need to use PHP and not Twig).

  1. Get an order by ID.
  2. Get ordered items.
  3. Get the addresses for the order.

Every help appreciated.

1 Answer 1

$order = \craft\commerce\elements\Order::find()->id($id)->one();

  foreach ($order->getLineItems() as $item) {
   // $item->description
   // $item->qty

  $billingAddress = $order->getBillingAddress();
  $shippingAddress = $order->getShippingAddress();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.