Magento 1.9 – Set Default for Radio Button Custom Option

ce-1.9.1.0custom-options

How do i set my radio button custom option to a default value? Now nothing is selected by default.

I suspect I can add or change something in –>

Mage/Catalog/Block/Product/View/Options/Type/Select.php?

Best Answer

Yes you are correct, the custom options are rendered from the file app/code/core/Mage/Catalog/Block/Product/View/Options/Type/Select.php

To set a set a radio button custom option to a default value, write this code

if($_value->getTitle() == 'Title_of_your_custom_option')
{
    $checked = 'checked';
}

before the below code

$selectHtml .= '<li>' . '<input type="' . $type . '" class="' . $class . ' ' . $require
                    . ' product-custom-option"'
                    . ($this->getSkipJsReloadPrice() ? '' : ' onclick="opConfig.reloadPrice()"')
                    . ' name="options[' . $_option->getId() . ']' . $arraySign . '" id="options_' . $_option->getId()
                    . '_' . $count . '" value="' . $htmlValue . '" ' . $checked . ' price="'
                    . $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false) . '" />'
                    . '<span class="label"><label for="options_' . $_option->getId() . '_' . $count . '">'
                    . $_value->getTitle() . ' ' . $priceStr . '</label></span>';
Related Topic