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.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow 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.
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;
}
}