0

How to show US country only in magento2 checkout frontend and admin orders side show the all countries

How to restrict all countries except US country in magento2 checkout.

2
  • you want on checkout billing address or shipping address only? – Dhiren Vasoya Jul 22 at 10:00
  • for Shipping address – venkata prasad Jul 22 at 10:31
1

Di.xml

<type name="Magento\Checkout\Block\Checkout\DirectoryDataProcessor">
    <plugin name="sr_checkout_country_list_fix"
            type="VendorName\Checkout\Plugin\Block\DirectoryDataProcessor" sortOrder="1"/>
</type>

Now app/code/VendorName/Checkout/Plugin/Block/DirectoryDataProcessor.php

<?php

namespace VendorName\Checkout\Plugin\Block;

use Magento\Checkout\Block\Checkout\DirectoryDataProcessor as BaseDirectoryDataProcessor;

class DirectoryDataProcessor
{
    /**
     * @param BaseDirectoryDataProcessor $subject
     * @param $jsLayout
     * @return mixed
     */
    public function afterProcess(
        BaseDirectoryDataProcessor $subject,
        $jsLayout
    ) {
        $finalCountries = [];
        $finalCountries[] = [
            'value' => 'US',
            'label' => 'United States',
            'is_region_visible' => 1,
            'is_default' => 1
        ];

        $jsLayout['components']['checkoutProvider']['dictionaries']['country_id'] = $finalCountries;
        return $jsLayout;
    }
}
0

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.