I am getting data of country code and ID and name from


using getCountriesInfo function.

Like this

    "id": "EG",
    "two_letter_abbreviation": "EG",
    "three_letter_abbreviation": "EGY",
    "full_name_locale": "Egypt",
    "full_name_english": "Egypt"
    "id": "KP",
    "two_letter_abbreviation": "KP",
    "three_letter_abbreviation": "PRK",
    "full_name_locale": "North Korea",
    "full_name_english": "North Korea"
    "id": "KW",
    "two_letter_abbreviation": "KW",
    "three_letter_abbreviation": "KWT",
    "full_name_locale": "Kuwait",
    "full_name_english": "Kuwait"

How can I get telephone code of that country as well in Magento 2 ?


Egypt telephone code +20
Kuwait telephone code +965
  • 1
    This type of feature does not exit at Magento. So you have to built this feature your self
    – Amit Bera
    Commented Jan 28, 2019 at 10:31
  • 1
    As Amit said in the comment this functionality doesn't exist in Magento by default. You can develop your custom module to achieve this. Store list of all countries with their country id and dial id somewhere. You can store them in a file or database and retrieve dial code filtering by country id. You can get list of dial code here gist.github.com/josephilipraja/8341837.
    – amitshree
    Commented Jan 28, 2019 at 13:45

1 Answer 1


You can create function in helper by enter all dial number with country code. I have created function like below:

public function getphonecode($code)
    $countrycode = array(

    $key = array_search($code,$countrycode);
    return $key;

You can get in phtml file like following:

$helper = $this->helper('Vendorname\Modulename\Helper\Data');
$allcounties = $helper->getphonecode($phonecode);

Hope it will work.

  • Thanks for the answer and +1 and accepting as an answer, Thanks for the efforts! Commented Sep 11, 2019 at 7:36

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.