0

I need to add a custom class to the country and state select box container in all forms expecially in shipping and billing address form on frontend?

0

Open file or override checkout

vendor/magento/module-checkout/view/frontend/layout/checkout_index_index.xml

search for the line <item name=”country_id” xsi:type=”array”> and

add class <item name="class" xsi:type="string">the-class</item>

0

add class at checkout page

VendorNameSpace\Module\etc\di.xml

<type name="Magento\Checkout\Block\Checkout\AttributeMerger">
    <plugin name="customAttributeMerger" type="VendorNameSpace\Module\Plugin\AttributeMergerPlugin"/>
</type>

AttributeMergerPlugin.php VendorNameSpace\Module\Plugin

<?php
namespace VendorNameSpace\Module\Plugin;

class AttributeMergerPlugin
{
    public function afterMerge(\Magento\Checkout\Block\Checkout\AttributeMerger $subject, $result)
    {
        // add Additional class for country
        if (array_key_exists('country_id', $result)) {
              $result['country_id']['additionalClasses'] = 'custom-class-country';
        }
        // add Additional class for city
        if (array_key_exists('city', $result)) {
            $result['city']['additionalClasses'] = 'cusotom-city';
        }

        return $result;
    }
}

Hope this will help you. thanks

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.