0

Basically when i add below code in system.xml file it load all the countries in admin side

<field id="showmethod" translate="label" type="select" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Show Method if Not Applicable</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <frontend_class>shipping-skip-hide</frontend_class>
                    <depends>
                        <field id="active">1</field>
                    </depends>
                </field>

but i want to get only one country in dropdown .Is there any way to do this?

  • for that instead of using Core source model, create you own source model with the required array – Piyush Nov 6 at 13:44
0

Try the below, Please change the labels as per the requirement

In your System.xml

<field id="showmethod" translate="label" type="select" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Show Method if Not Applicable</label>
                    <source_model>{Namespace}\{Module}\Model\Config\Source\CountryList</source_model>
                    <frontend_class>shipping-skip-hide</frontend_class>
                    <depends>
                        <field id="active">1</field>
                    </depends>
 </field>    

In Your custom module under app/code/{Namespace}/{Module}/Model/Config/source/

<?php 
namespace {Namespace}\{Module}\Model\Config\source;

class CountryList implements \Magento\Framework\Option\ArrayInterface
{
 public function toOptionArray()
 {
  return [
    ['value' => 'USA', 'label' => __('USA')]    
  ];
 }
}

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.