{"id":16348,"date":"2025-06-04T11:55:28","date_gmt":"2025-06-04T06:25:28","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/?p=16348"},"modified":"2025-06-05T09:41:41","modified_gmt":"2025-06-05T04:11:41","slug":"downloadable-product-options-from-order-items-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/downloadable-product-options-from-order-items-in-magento-2\/","title":{"rendered":"How to Get Selected Downloadable Product Options from Order Items in Magento 2?\u00a0"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">While<a href=\"https:\/\/meetanshi.com\/blog\/create-downloadable-products-in-magento-2\/\"> creating downloadable products in Magento 2<\/a>, there&#8217;s an important setting that determines how customers access the downloadable files: <strong>&#8220;Links Purchased Separately.&#8221;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This setting defines whether customers can purchase individual links or only as a complete bundle.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1999\" height=\"806\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately.png\" alt=\"Enable Links Purchased Separately\" class=\"wp-image-16349\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately.png 1999w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately-250x101.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately-700x282.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately-768x310.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately-1536x619.png 1536w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately-403x162.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately-964x389.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/06\/Enable-Links-Purchased-Separately-120x48.png 120w\" sizes=\"auto, (max-width: 1999px) 100vw, 1999px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">If you enable this option by checking the box, each downloadable link will be treated as a separate item. This allows customers to select and purchase only the specific files they want.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This option can be useful when you are selling a digital product like a course, media content or a software module.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re selling an entire course as a downloadable product and want to give customers the option to buy just one specific lesson instead of the whole course, this feature is helpful.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a Magento developer, you may often need to retrieve the exact downloadable options selected by a customer for a particular order item via code. This becomes essential in scenarios such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Displaying downloadable links in the customer\u2019s order history<br><\/li>\n\n\n\n<li>Indicating which downloadable files were purchased<br><\/li>\n\n\n\n<li>Including this information in PDF invoices<br><\/li>\n\n\n\n<li>Developing backend or frontend features that rely on this data<br><\/li>\n\n\n\n<li>Adding downloadable link titles in order confirmation emails<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Get Selected Downloadable Product Options from Order Items in Magento 2?&nbsp;<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Integrate the below solution to get access to this option.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n\nif($_item->getProduct()->getTypeId() == 'downloadable'){\n$purchased = $objectManager->create('Magento\\Downloadable\\Model\\Link\\PurchasedFactory')->create()->load($_item->getId(), 'order_item_id');\n                    $purchasedItemCollectionFactory = $objectManager->create('Magento\\Downloadable\\Model\\ResourceModel\\Link\\Purchased\\Item\\CollectionFactory');\n                    $purchasedItems = $purchasedItemCollectionFactory->create()\n                        ->addFieldToFilter('order_item_id', $_item->getId());\n\n                    foreach ($purchasedItems as $purchasedItem) {\n                        $downloadableItems[] = [\n                            'link_title' => $purchased->getLinkSectionTitle(),\n                            'option_title' => $purchasedItem->getLinkTitle()\n                        ];\n                    }\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, $_items is an object of the Sales Order Item.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The above code populates the $downloadableItems array with titles of each downloadable file linked to the order item.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Simply, use this solution to get selected downloadable product options from order items in Magento 2.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While creating downloadable products in Magento 2, there&#8217;s an important setting that determines how customers access the downloadable files: &#8220;Links Purchased Separately.&#8221; This setting defines&#8230;<\/p>\n","protected":false},"author":5,"featured_media":16397,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-16348","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/16348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=16348"}],"version-history":[{"count":1,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/16348\/revisions"}],"predecessor-version":[{"id":16351,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/16348\/revisions\/16351"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media\/16397"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=16348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=16348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=16348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}