2

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

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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