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? Commented Jul 22, 2021 at 10:00
  • for Shipping address Commented Jul 22, 2021 at 10:31

1 Answer 1

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;
    }
}
1
  • How to restict in cart page estimate shipping and tax Commented Aug 13, 2021 at 12:45

Your Answer

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

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