{"id":1752,"date":"2021-05-05T10:41:30","date_gmt":"2021-05-05T10:41:30","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-product-custom-options-value-from-cart-and-order-in-magento-2\/"},"modified":"2025-07-16T17:53:59","modified_gmt":"2025-07-16T12:23:59","slug":"get-product-custom-options-value-from-cart-and-order-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-product-custom-options-value-from-cart-and-order-in-magento-2\/","title":{"rendered":"How to Get Product Custom Options Value From Cart and Order in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The customers like to receive a personalized experience while purchasing anything from the online store, especially when it comes to the custom options assigned to a particular product. The more options, the more enhanced the customer experience!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An easy way to offer a selection of options with various text, selection, and date input types is to add&nbsp;<a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-admin\/catalog\/introduction\" target=\"_blank\" rel=\"noreferrer noopener\">customizable options<\/a>&nbsp;to a product.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you add custom options to a product in\u00a0Magento 2, you allow your customers to choose product options according to their needs without relying on the product attributes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After adding custom options to the product page, what if you want to deal with third-party API and need to get that product custom option value from cart or order? What if you\u2019re going to pass that custom option value immediately after the order placed?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can&nbsp;<strong><em>get product custom options value from cart and order in Magento 2<\/em><\/strong>&nbsp;by following the below solution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Get Product Custom Options Value From Cart and Order in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the below code in the helper file.<\/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=\"\">&lt;?php\n\nnamespace Vendor\\Extension\\Helper;\n\nuse Magento\\Checkout\\Model\\Cart;\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Sales\\Model\\Order;\n\nclass Data extends AbstractHelper\n{\n    protected $orderModel;\n    protected $quote;\n\n    public function __construct(\n        Context $context,\n        Order $orderModel,\n        Cart $cart\n    )\n    {\n        $this->orderModel = $orderModel;\n        $this->quote = $cart;\n        parent::__construct($context);\n    }\n\n    public function getProductOptions()\n    {\n        $orderId = 23;\n        $order = $this->orderModel->load($orderId);\n        $orderItems = $order->getAllVisibleItems();\n\n        foreach ($orderItems as $item) {\n            $options = $item->getProductOptions();\n\n            $AllOptionsData = $options;\n\n            if (isset($options['attributes_info'])) {\n                $attributesOptions = $options['attributes_info'];\n\n                $optionValue = $attributesOptions['option_value'];\n            }\n\n            if (isset($options['additional_options'])) {\n                $additionalOptions = $options['additional_options'];\n\n                $optionValue = $additionalOptions['option_value'];\n            }\n\n            if (isset($options['options'])) {\n                $productOptions = $options['options'];\n\n                $optionId = $productOptions['option_id'];\n                $optionValue = $productOptions['option_value'];\n            }\n        }\n    }\n\n    public function getCartItemOptions()\n    {\n        $cartItems = $this->quote->getItems();\n        foreach ($cartItems as $item) {\n            $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());\n\n            $AllOptionsData = $options; \/\/ you check particular options data same as above.\n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also Read:&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/sql-query-to-get-all-products-with-custom-options-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQL query to get all products with custom options in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, do share the post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The customers like to receive a personalized experience while purchasing anything from the online store, especially when it comes to the custom options assigned to&#8230;<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1752","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1752","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\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1752"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1752\/revisions"}],"predecessor-version":[{"id":18088,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1752\/revisions\/18088"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}