2

I want SKU value of product's selected custom option on onepage.

Can somebody help me on this ?

Thank you.

2
  • need to cart page or product view page?
    – Abdul
    Commented Dec 9, 2015 at 11:29
  • I need this on cart page.
    – Elizabeth
    Commented Dec 9, 2015 at 11:30

1 Answer 1

3

Try bellow code

<?php
$options = $_item->getBuyRequest()->getData('options');

foreach ($options as $key => $value) {
     $optionData = $_item->getProduct()->getOptionById($key);
     if($optionData['type'] == 'drop_down') {
         foreach ($optionData->getValues() as $v) {
             if ($v['option_type_id'] == $value) {
                 echo $v->getSku();
                 echo "<br>";
                 break;
             }
         }
     }
     elseif ($optionData['type'] == 'field') {
       echo $optionData['sku'];   
     }

 }

?>
5
  • I have two custom options, first's input type is drop down and next is Field.Using your code I only get an sku value of custom option which is selected from field input type. But cannot getting sku of custom option selected from Drop down.
    – Elizabeth
    Commented Dec 9, 2015 at 11:39
  • updated my answer. try that now. Commented Dec 9, 2015 at 12:02
  • updated my answer as per condition. Commented Dec 9, 2015 at 12:13
  • updated again for selected option condition. Commented Dec 9, 2015 at 13:17
  • any idea how to obtain the selected custom option from options.phtml? Commented Oct 3, 2017 at 0:27

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.