1

I want to change name prefix to radio button in billing and shipping address.
How can I do that possible?
I want to change this in Customer pages also.

enter image description here

2
  • Can you write more about it?
    – Sohel Rana
    Jun 2 '18 at 9:49
  • I have edit Question Jun 2 '18 at 13:25
6
+50

For checkout:

Step 1: VendorName/ModuleName/etc/di.xml


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="sr_ModuleName_checkout_layout_processor" type="VendorName\ModuleName\Plugin\Block\LayoutProcessor" sortOrder="1"/>
    </type>
</config>

Step 2: VendorName/ModuleName/Plugin/Block/LayoutProcessor.php


namespace VendorName\ModuleName\Plugin\Block;

class LayoutProcessor
{
    /**
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
    public function afterProcess(
        \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
        array $jsLayout
    ) {
        if(isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['shipping-address-fieldset'])) {

            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['prefix']['component'] = "Magento_Ui/js/form/element/checkbox-set";

            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['prefix']['config']['elementTmpl'] = "ui/form/element/checkbox-set";

            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
            ['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['prefix']['config']['multiple'] = false;
        }

        if(isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['payments-list'])) {
            $paymentsList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['payments-list']['children'];

            foreach ($paymentsList as $paymentCode => $payment) {
                if(strpos($paymentCode, '-form') === false) {
                    continue;
                }
                $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'][$paymentCode]['children']['form-fields']['children']['prefix']['component'] = "Magento_Ui/js/form/element/checkbox-set";
                $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'][$paymentCode]['children']['form-fields']['children']['prefix']['config']['elementTmpl'] = "ui/form/element/checkbox-set";
                $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'][$paymentCode]['children']['form-fields']['children']['prefix']['config']['multiple'] = false;
            }
        }
        if(isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['afterMethods']['children']['billing-address-form'])) {
            $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']['prefix']['component'] = "Magento_Ui/js/form/element/checkbox-set";

            $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']['prefix']['config']['elementTmpl'] = "ui/form/element/checkbox-set";

            $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
            ['payment']['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children']['prefix']['config']['multiple'] = false;
        }

        return $jsLayout;
    }
}

For customer edit page:

Overwrite vendor/magento/module-customer/view/frontend/templates/widget/name.phtml template inside your module or theme. Change prefix dropdown to checkbox.

9
  • thats perfect solution for me!!.Also nice module SR_ModifiedCheckout is Jun 4 '18 at 9:36
  • @Sohel Bhai, Its not working with M2.2.4 Getting error for checkbox-set.js Any idea ?
    – anonymous
    Jun 4 '18 at 9:58
  • @Vivek working fine for me version M2.2.4. What is the error?
    – Sohel Rana
    Jun 4 '18 at 10:10
  • @Sohel Bhai, Its working, I forgot to enable Prefix for customers. Great Work. Continue..
    – anonymous
    Jun 4 '18 at 10:15
  • 1
    @Ketan check updated answer.
    – Sohel Rana
    Jun 5 '18 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.