Anu Mary Anu Mary - 6 months ago 49
PHP Question

How to get order details in product detail page in magento 2

How show the past order details of a particular product in product details page.
The version that i am using is magento 2.0.3.

Answer

Try this:

$tableOrder = $this->_resource->getTableName('sales_order'); 
$object_manager = \Magento\Framework\App\ObjectManager::getInstance();

$collection=$object_manager->get("Magento\Sales\Model\Order\Item")->getCollection()->addFieldToFilter("product_id",Your Product Id);
$collection->getSelect()->join( array('order'=> $tableOrder), 'order.entity_id = main_table.order_id', array("*"));

print_r($collection->getData());