0

I want to make the Checkbox checked by Default in checkout page. I have used below code it is displaying the Checkbox but it is not checked by Default, Can you please suggest where i was wrong.

 $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
                    ['shippingAddress']['children']['shipping-address-fieldset']['children']['newsletter_subscribe'] = [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/checkbox',
                    'options' => [],
                    'id' => 'delivery-date'
                ],
                'dataScope' => 'shippingAddress.newsletter_subscribe',
                'label' => $label,
                'provider' => 'checkoutProvider',
                'visible' => true,
                'checked' => 'checked',
                'validation' => [],
                'sortOrder' => 250,
                'id' => 'newsletter-subscribe'
            ];
1
  • instead use 'checked' => true, Commented Jul 11, 2016 at 6:02

2 Answers 2

1

You can try with below code,

 $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
                    ['shippingAddress']['children']['shipping-address-fieldset']['children']['newsletter_subscribe'] = [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/checkbox',
                    'options' => [],
                    'id' => 'delivery-date'
                ],
                'dataScope' => 'shippingAddress.newsletter_subscribe',
                'label' => $label,
                'provider' => 'checkoutProvider',
                'visible' => true,
                'checked' => true,
                'validation' => [],
                'sortOrder' => 250,
                'id' => 'newsletter-subscribe'
            ];

Remove pub/static folder and run deploy command,

php bin/magento setup:static-content:deploy

Try again.

1
  • Is this code is worked for you? Commented Jul 11, 2016 at 6:09
0

This given below code apply after. You should get checkout checkbox default value to tick always

$shippingConfig = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']; 
$customcheckboxcode = 'email_update';

        $customCheckbox = [
            'component' => 'Magento_Ui/js/form/element/abstract',
            'config' => [
                'customScope' => 'shippingAddress.email_update',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/checkbox',
                'options' => [],
                'id' => 'email_update_checkbox'
            ],
            'dataScope' => $customcheckboxcode,
            'label' => '',
            'provider' => 'checkoutProvider',
            'description' => 'We would like to send you email updates and reminders about your basket.',
            'visible' => true,
            'checked' => false,
            'default'=> true,
            'validation' => [],
            'sortOrder' => 10,
            'id' => 'email_update_checkbox'
        ];

        $shippingConfig['children']['shipping-address-fieldset']['children'][$customcheckboxcode] = $customCheckbox;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.