0

How to get this https://prnt.sc/HE4LFsRji9fs Customizable option data in a phtml file. I want to data in like in this format...

<div class="field required">
            <label class="label" for="select_69">
            <span>Options</span>
            </label>
            <div class="control">
            <select name="options[69]" id="select_69" class=" required product-custom-option admin__control-select" title="" data-selector="options[69]" aria-required="true"><option value="">-- Please Select --</option><option value="192" price="30">straight charge +£30.00</option></select></div></div>

1 Answer 1

0

Here, I am sharing the solution.. How to get Customizable option data in a phtml file.

<?php 
$product = $block->getProduct();
$options = $product->getOptions();
if ($options && !empty($options)) {
    foreach ($options as $option) {
        if ($option->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DROP_DOWN) {   
            ?>
            
            <div class="field required ">
                <label class="label" for="select_<?php echo $option->getId(); ?>">
                    <span><h4><?php echo $option->getTitle(); ?></h4></span>
                </label>
                <div class="control">
                    <select name="options[<?php echo $option->getId(); ?>]" id="select_<?php echo $option->getId(); ?>"
                            class="required product-custom-option admin__control-select select-option"
                            title="<?php echo $option->getTitle(); ?>"
                            data-selector="options[<?php echo $option->getId(); ?>]" aria-required="true">
                        <option value=""><?php echo __('-- Please Select --'); ?></option>
                        <?php foreach ($option->getValues() as $value) { ?>
                            <option value="<?php echo $value->getId(); ?>" price="<?php echo $value->getPrice(); ?>">
                                <?php echo $value->getTitle(); ?>
                                <?php if ($value->getPrice() != 0) { ?>
                                    <?php echo __('+'); ?><?php echo $value->getPrice(); ?>
                                <?php } ?>
                            </option>
                        <?php } ?>
                    </select>
                </div>
            </div>
            <?php
          }
      }
   }

?>

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.