Magento – How to add custom product ‘option’ to container2

magento-1.7product

I have some two options added to products via the admin panel. What I want to do is insert some custom html between these options. Is it possible to do this programmatically ?

Something similar to:

$_product->addOption(
    array(
        'type' => 'html',
        'value' => '<!--html to go here-->',
        'position' => 1
    ) );

where the type would require a new view script that would just echo the option value.

Alternatively, is there a way to echo out the options independently? e.g.:

echo $_product->getOption(0)->toHtml(), // echo first option
     $myHtmlHere,                       // echo my html
     $_product->getOption(1)->toHtml(); // echo second option

Best Answer

The easiest way to do it is to loop through custom options of your product and then depending on option ID insert your custom HTML:

if($_product->hasOptions()) {
    foreach ($_product->getOptions() as $option) {
        echo $option->getOptionHtml();

        if ($option->getId() == [your-option-id]) {
            // output your custom HTML here.
        }
    }
}
Related Topic