To add a radio button on the address section.

At first, we need to copy edit.phtml from /var/www/html/kwikclamp/vendor/magento/module-customer/view/frontend/templates/address/ and paste it in /var/www/html/kwikclamp/app/design/frontend/Codazon/fastest/mechanic_tools/Magento_Customer/templates/address/edit.phtml

And we need to write code on edit.phtml file.

<div class="field delivery required">
                    <label class="label" for="delivery_to"><span><?php echo $block->getAttributeData()->getFrontendLabel('delivery_to'); ?></span></label>
                    <div class="control">
                        <input type="radio" name="delivery_to"
                               value="0"
                               title="<?php echo __('Home') ?>"
                               class="input-text" id="delivery_to"
                            <?= ($delivery == 0) ? "checked" : ''?>>
                        <span>Home</span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="delivery_to"
                               value="1"
                               title="<?php echo __('Business') ?>"
                               class="input-text" id="delivery_to" <?= ($delivery == 1) ? "checked" : ''?>>
                        <span>Business</span>
                    </div>
                </div>

We will get output as shown below

We need to add if condition so that we can add a New address without error. If we don’t write the condition the page will be broken

We should write this code above or below the Radio button code.

<?php
       $address=$block->getAddress()->getCustomAttribute('delivery_to');
       $delivery=null;
       if ( $address !=null){
            $delivery=$block->getAddress()->getCustomAttribute('delivery_to')->getValue();
       }
        ?>

After that, we need to do

  1. php bin/magento setup:upgrade
  2. php bin/magento setup:static-content:deploy -f
  3. sudo chmod 777 -R /var/www/html/kwikclamp/

Leave a comment

Your email address will not be published. Required fields are marked *