1

I have a Custom attribute name ( product string ) on Product in which i have save a string i want to get that custom attribute value for ordered product.

I have getting the ordered product by this code

 $orderId = 32;
 $order = $block->getOrderData($orderId);
 foreach ($order->getAllVisibleItems() as $_item) {
 echo $_item->getId();
 echo $_item->getSku();
 echo $_item->getName();
 echo $_item->getProductType();
 echo $_item->getQtyOrdered();
 echo "<pre>";print_r($_item->debug());
}
asked Aug 7, 2020 at 15:20

1 Answer 1

2

You can get it with $item->getProduct()->getData('attribute_code_here')

But there is a problem.
Actually a few:

  • Product may have been deleted
  • the attribute value has been changed after the order was placed.
  • the attribute may have been deleted

The best approach would be to save the value of the product attribute on the order item when the order is placed.
Here are some examples on how you can do that

answered Aug 7, 2020 at 15:33
1
  • Thanks for the response and help. Actually my requirement is different anyway thanks for the link. @Marius Commented Aug 8, 2020 at 6:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.