<?php
/**
 * Define amazon RegionName and host and also RegionCode
 *
 * @return string[][]
 */
function ams_get_amazon_regions()
{
    $regions = array(
        'com.au' => array('RegionName' => 'Australia', 'Host' => 'webservices.amazon.com.au', 'RegionCode' => 'us-west-2'),
        'com.br' => array('RegionName' => 'Brazil', 'Host' => 'webservices.amazon.com.br', 'RegionCode' => 'us-east-1'),
        'ca' => array('RegionName' => 'Canada', 'Host' => 'webservices.amazon.ca', 'RegionCode' => 'us-east-1'),
        'cn' => array('RegionName' => 'China', 'Host' => 'webservices.amazon.cn', 'RegionCode' => 'us-west-2'),
        'fr' => array('RegionName' => 'France', 'Host' => 'webservices.amazon.fr', 'RegionCode' => 'eu-west-1'),
        'de' => array('RegionName' => 'Germany', 'Host' => 'webservices.amazon.de', 'RegionCode' => 'eu-west-1'),
        'in' => array('RegionName' => 'India', 'Host' => 'webservices.amazon.in', 'RegionCode' => 'eu-west-1'),
        'it' => array('RegionName' => 'Italy', 'Host' => 'webservices.amazon.it', 'RegionCode' => 'eu-west-1'),
        'jp' => array('RegionName' => 'Japan', 'Host' => 'webservices.amazon.co.jp', 'RegionCode' => 'us-west-2'),
        'mx' => array('RegionName' => 'Mexico', 'Host' => 'webservices.amazon.com.mx', 'RegionCode' => 'us-east-1'),
        'nl' => array('RegionName' => 'Netherlands', 'Host' => 'webservices.amazon.nl', 'RegionCode' => 'eu-west-1'),
        'sa' => array('RegionName' => 'Saudi Arabia', 'Host' => 'webservices.amazon.sa', 'RegionCode' => 'eu-west-1'),
        'sg' => array('RegionName' => 'Singapore', 'Host' => 'webservices.amazon.sg', 'RegionCode' => 'us-west-2'),
        'es' => array('RegionName' => 'Spain', 'Host' => 'webservices.amazon.es', 'RegionCode' => 'eu-west-1'),
        'com.tr' => array('RegionName' => 'Turkey', 'Host' => 'webservices.amazon.com.tr', 'RegionCode' => 'eu-west-1'),
        'ae' => array('RegionName' => 'United Arab Emirates', 'Host' => 'webservices.amazon.ae', 'RegionCode' => 'eu-west-1'),
        'co.uk' => array('RegionName' => 'United Kingdom', 'Host' => 'webservices.amazon.co.uk', 'RegionCode' => 'eu-west-1'),
        'com' => array('RegionName' => 'United States', 'Host' => 'webservices.amazon.com', 'RegionCode' => 'us-east-1'),
    );
    return $regions;
}
function ams_get_amazon_regions_limited()
{
    $regions = array(
        'ca' => array('RegionName' => 'Canada', 'Host' => 'webservices.amazon.ca', 'RegionCode' => 'us-east-1'),
        'fr' => array('RegionName' => 'France', 'Host' => 'webservices.amazon.fr', 'RegionCode' => 'eu-west-1'),
        'de' => array('RegionName' => 'Germany', 'Host' => 'webservices.amazon.de', 'RegionCode' => 'eu-west-1'),
        'jp' => array('RegionName' => 'Japan', 'Host' => 'webservices.amazon.co.jp', 'RegionCode' => 'us-west-2'),
        'co.uk' => array('RegionName' => 'United Kingdom', 'Host' => 'webservices.amazon.co.uk', 'RegionCode' => 'eu-west-1'),
        'com' => array('RegionName' => 'United States', 'Host' => 'webservices.amazon.com', 'RegionCode' => 'us-east-1'),
    );
    return $regions;
}
/**
 * Total products information is brought through this function
 *
 * @return array
 */
function ams_get_all_products_info()
{
    global $wpdb;
    $results = $wpdb->get_results(
        $wpdb->prepare(
            "SELECT DISTINCT $wpdb->posts.ID, $wpdb->postmeta.meta_value
             FROM $wpdb->posts, $wpdb->postmeta
             WHERE $wpdb->posts.ID  = $wpdb->postmeta.post_id
             AND $wpdb->posts.post_type  = %s
             AND $wpdb->postmeta.meta_key = %s
             ",
            'product', '_wca_amazon_affiliate_asin'
        )
    );
    $products_search_count = get_option('wca_products_search_count');
    $data = array();
    $total_view_count = 0;
    $total_product_direct_redirected = 0;
    $total_product_added_to_cart = 0;
    foreach ($results as $row) {
        $data['asin'][] = $row->meta_value;
        $data['id'][] = $row->ID;
        $data['product_id'][$row->ID]['method'] = get_post_meta($row->ID, '_import_method', true);
        $data['product_id'][$row->ID]['region'] = get_post_meta($row->ID, '_region', true);
        $data['product_id'][$row->ID]['url'] = get_post_meta($row->ID, '_detail_page_url', true);
        $view = get_post_meta($row->ID, 'ams_product_views_count', true);
        $total_view_count = $total_view_count + (int) $view;
        $product_direct_redirected = get_post_meta($row->ID, 'ams_product_direct_redirected', true);
        $total_product_direct_redirected = $total_product_direct_redirected + (int) $product_direct_redirected;
        $product_added_to_cart = get_post_meta($row->ID, 'ams_product_added_to_cart', true);
        $total_product_added_to_cart = $total_product_added_to_cart + (int) $product_added_to_cart;
    }
    $data['total_view_count'] = $total_view_count;
    $data['total_product_direct_redirected'] = $total_product_direct_redirected;
    $data['total_product_added_to_cart'] = $total_product_added_to_cart;
    $data['products_count'] = (isset($data['product_id'])) ? sizeof($data['product_id']) : 0;
    $data['products_search_count'] = $products_search_count;
    return $data;
}
/**
 * Amazon affiliate departments country base
 *
 * @return string[][]
 */
function ams_amazon_departments()
{
    $cat = array(
        'com.au' => array(
            'All' => 'All Departments',
            'Automotive' => 'Automotive',
            'Baby' => 'Baby',
            'Beauty' => 'Beauty',
            'Books' => 'Books',
            'Computers' => 'Computers',
            'Electronics' => 'Electronics',
            'EverythingElse' => 'Everything Else',
            'Fashion' => 'Clothing & Shoes',
            'GiftCards' => 'Gift Cards',
            'HealthPersonalCare' => 'Health, Household & Personal Care',
            'HomeAndKitchen' => 'Home & Kitchen',
            'KindleStore' => 'Kindle Store',
            'Lighting' => 'Lighting',
            'Luggage' => 'Luggage & Travel Gear',
            'MobileApps' => 'Apps & Games',
            'MoviesAndTV' => 'Movies & TV',
            'Music' => 'CDs & Vinyl',
            'OfficeProducts' => 'Stationery & Office Products',
            'PetSupplies' => 'Pet Supplies',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports, Fitness & Outdoors',
            'ToolsAndHomeImprovement' => 'Home Improvement',
            'ToysAndGames' => 'Toys & Games',
            'VideoGames' => 'Video Games',
        ),
        'com.br' => array(
            'All' => 'Todos os departamentos',
            'Books' => 'Livros',
            'Computers' => 'Computadores e Informática',
            'Electronics' => 'Eletrônicos',
            'HomeAndKitchen' => 'Casa e Cozinha',
            'KindleStore' => 'Loja Kindle',
            'MobileApps' => 'Apps e Jogos',
            'OfficeProducts' => 'Material para Escritório e Papelaria',
            'ToolsAndHomeImprovement' => 'Ferramentas e Materiais de Construção',
            'VideoGames' => 'Games',
        ),
        'ca' => array(
            'All' => 'All Department',
            'Apparel' => 'Clothing & Accessories',
            'Automotive' => 'Automotive',
            'Baby' => 'Baby',
            'Beauty' => 'Beauty',
            'Books' => 'Books',
            'Classical' => 'Classical Music',
            'Electronics' => 'Electronics',
            'EverythingElse' => 'Everything Else',
            'ForeignBooks' => 'English Books',
            'GardenAndOutdoor' => 'Patio, Lawn & Garden',
            'GiftCards' => 'GiftCards',
            'GroceryAndGourmetFood' => 'Grocery & Gourmet Food',
            'Handmade' => 'Handmade',
            'HealthPersonalCare' => 'Health & Personal Care',
            'HomeAndKitchen' => 'Home & Kitchen',
            'Industrial' => 'Industrial & Scientific',
            'Jewelry' => 'Jewelry',
            'KindleStore' => 'Kindle Store',
            'Luggage' => 'Luggage & Bags',
            'LuxuryBeauty' => 'Luxury Beauty',
            'MobileApps' => 'Apps & Games',
            'MoviesAndTV' => 'Movies & TV',
            'Music' => 'Music',
            'MusicalInstruments' => 'Musical Instruments, Stage & Studio',
            'OfficeProducts' => 'Office Products',
            'PetSupplies' => 'Pet Supplies',
            'Shoes' => 'Shoes & Handbags',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports & Outdoors',
            'ToolsAndHomeImprovement' => 'Tools & Home Improvement',
            'ToysAndGames' => 'Toys & Games',
            'VHS' => 'VHS',
            'VideoGames' => 'Video Games',
            'Watches' => 'Watches',
        ),
        'cn' => array(
            'All' => 'All Departments',
        ),
        'fr' => array(
            'All' => 'Toutes nos catégories',
            'Apparel' => 'Vêtements et accessoires',
            'Appliances' => 'Gros électroménager',
            'Automotive' => 'Auto et Moto',
            'Baby' => '  Bébés & Puériculture',
            'Beauty' => 'Beauté et Parfum',
            'Books' => 'Livres en français',
            'Computers' => 'Informatique',
            'DigitalMusic' => 'Téléchargement de musique',
            'Electronics' => 'High-Tech',
            'EverythingElse' => 'Autres',
            'Fashion' => 'Mode',
            'ForeignBooks' => 'Livres anglais et étrangers',
            'GardenAndOutdoor' => 'Jardin',
            'GiftCards' => 'Boutique chèques-cadeaux',
            'GroceryAndGourmetFood' => 'Epicerie',
            'Handmade' => 'Handmade',
            'HealthPersonalCare' => 'Hygiène et Santé',
            'HomeAndKitchen' => 'Cuisine & Maison',
            'Industrial' => 'Secteur industriel & scientifique',
            'Jewelry' => 'Bijoux',
            'KindleStore' => 'Boutique Kindle',
            'Lighting' => 'Luminaires et Eclairage',
            'Luggage' => 'Bagages',
            'LuxuryBeauty' => 'Beauté Prestige',
            'MobileApps' => 'Applis & Jeux',
            'MoviesAndTV' => 'DVD & Blu-ray',
            'Music' => 'Musique : CD & Vinyles',
            'MusicalInstruments' => 'Instruments de musique & Sono',
            'OfficeProducts' => 'Fournitures de bureau',
            'PetSupplies' => 'Animalerie',
            'Shoes' => 'Chaussures et Sacs',
            'Software' => 'Logiciels',
            'SportsAndOutdoors' => 'Sports et Loisirs',
            'ToolsAndHomeImprovement' => 'Bricolage',
            'ToysAndGames' => 'Jeux et Jouets',
            'VHS' => 'VHS',
            'VideoGames' => 'Jeux vidéo',
            'Watches' => 'Montres',
        ),
        'de' => array(
            'All' => 'Alle Kategorien',
            'AmazonVideo' => 'Prime Video',
            'Apparel' => 'Bekleidung',
            'Appliances' => 'Elektro-Großgeräte',
            'Automotive' => 'Auto & Motorrad',
            'Baby' => 'Baby',
            'Beauty' => 'Beauty',
            'Books' => 'Bücher',
            'Classical' => 'Klassik',
            'Computers' => 'Computer & Zubehör',
            'DigitalMusic' => 'Musik-Downloads',
            'Electronics' => 'Elektronik & Foto',
            'EverythingElse' => 'Sonstiges',
            'Fashion' => 'Fashion',
            'ForeignBooks' => 'Bücher (Fremdsprachig)',
            'GardenAndOutdoor' => 'Garten',
            'GiftCards' => 'Geschenkgutscheine',
            'GroceryAndGourmetFood' => 'Lebensmittel & Getränke',
            'Handmade' => 'Handmade',
            'HealthPersonalCare' => 'Drogerie & Körperpflege',
            'HomeAndKitchen' => 'Küche, Haushalt & Wohnen',
            'Industrial' => 'Gewerbe, Industrie & Wissenschaft',
            'Jewelry' => 'Schmuck',
            'KindleStore' => 'Kindle-Shop',
            'Lighting' => 'Beleuchtung',
            'Luggage' => 'Koffer, Rucksäcke & Taschen',
            'LuxuryBeauty' => 'Luxury Beauty',
            'Magazines' => 'Zeitschriften',
            'MobileApps' => 'Apps & Spiele',
            'MoviesAndTV' => 'DVD & Blu-ray',
            'Music' => 'Musik-CDs & Vinyl',
            'MusicalInstruments' => 'Musikinstrumente & DJ-Equipment',
            'OfficeProducts' => 'Bürobedarf & Schreibwaren',
            'PetSupplies' => 'Haustier',
            'Photo' => 'Kamera & Foto',
            'Shoes' => 'Schuhe & Handtaschen',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sport & Freizeit',
            'ToolsAndHomeImprovement' => 'Baumarkt',
            'ToysAndGames' => 'Spielzeug',
            'VHS' => 'VHS',
            'VideoGames' => 'Games',
            'Watches' => 'Uhren',
        ),
        'in' => array(
            'All' => 'All Categories',
            'Apparel' => 'Clothing & Accessories',
            'Appliances' => 'Appliances',
            'Automotive' => 'Car & Motorbike',
            'Beauty' => 'Beauty',
            'Books' => 'Books',
            'Collectibles' => 'Collectibles',
            'Computers' => 'Computers & Accessories',
            'Electronics' => 'Electronics',
            'EverythingElse' => 'Everything Else',
            'Fashion' => 'Amazon Fashion',
            'Furniture' => 'Furniture',
            'GardenAndOutdoor' => 'Garden & Outdoors',
            'GiftCards' => 'Gift Cards',
            'GroceryAndGourmetFood' => 'Grocery & Gourmet Foods',
            'HealthPersonalCare' => 'Health & Personal Care',
            'HomeAndKitchen' => 'Home & Kitchen',
            'Industrial' => 'Industrial & Scientific',
            'Jewelry' => 'Jewellery',
            'KindleStore' => 'Kindle Store',
            'Luggage' => 'Luggage & Bags',
            'LuxuryBeauty' => 'Luxury Beauty',
            'MobileApps' => 'Apps & Games',
            'MoviesAndTV' => 'Movies & TV Shows',
            'Music' => 'Music',
            'MusicalInstruments' => 'Musical Instruments',
            'OfficeProducts' => 'Office Products',
            'PetSupplies' => 'Pet Supplies',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports, Fitness & Outdoors',
            'ToolsAndHomeImprovement' => 'Tools & Home Improvement',
            'ToysAndGames' => 'Toys & Games',
            'VideoGames' => 'Video Games',
            'Watches' => 'Watches',
        ),
        'it' => array(
            'All' => 'Tutte le categorie',
            'Apparel' => 'Abbigliamento',
            'Appliances' => 'Grandi elettrodomestici',
            'Automotive' => 'Auto e Moto',
            'Baby' => 'Prima infanzia',
            'Beauty' => 'Bellezza',
            'Books' => 'Libri',
            'Computers' => 'Informatica',
            'DigitalMusic' => 'Musica Digitale',
            'Electronics' => 'Elettronica',
            'EverythingElse' => 'Altro',
            'Fashion' => 'Moda',
            'ForeignBooks' => 'Libri in altre lingue',
            'GardenAndOutdoor' => 'Giardino e giardinaggio',
            'GiftCards' => 'Buoni Regalo',
            'GroceryAndGourmetFood' => 'Alimentari e cura della casa',
            'Handmade' => 'Handmade',
            'HealthPersonalCare' => 'Salute e cura della persona',
            'HomeAndKitchen' => 'Casa e cucina',
            'Industrial' => 'Industria e Scienza',
            'Jewelry' => 'Gioielli',
            'KindleStore' => 'Kindle Store',
            'Lighting' => 'Illuminazione',
            'Luggage' => 'Valigeria',
            'MobileApps' => 'App e Giochi',
            'MoviesAndTV' => 'Film e TV',
            'Music' => 'CD e Vinili',
            'MusicalInstruments' => 'Strumenti musicali e DJ',
            'OfficeProducts' => 'Cancelleria e prodotti per ufficio',
            'PetSupplies' => 'Prodotti per animali domestici',
            'Shoes' => 'Scarpe e borse',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sport e tempo libero',
            'ToolsAndHomeImprovement' => 'Fai da te',
            'ToysAndGames' => 'Giochi e giocattoli',
            'VideoGames' => 'Videogiochi',
            'Watches' => 'Orologi',
        ),
        'jp' => array(
            'All' => 'All Departments',
            'AmazonVideo' => 'Prime Video',
            'Apparel' => 'Clothing & Accessories',
            'Appliances' => 'Large Appliances',
            'Automotive' => 'Car & Bike Products',
            'Baby' => 'Baby & Maternity',
            'Beauty' => 'Beauty',
            'Books' => 'Japanese Books',
            'Computers' => 'Computers & Accessories',
            'CreditCards' => 'Credit Cards',
            'DigitalMusic' => 'Digital Music',
            'Electronics' => 'Electronics & Cameras',
            'EverythingElse' => 'Everything Else',
            'Fashion' => 'Fashion',
            'FashionBaby' => 'Kids & Baby',
            'FashionMen' => 'Men',
            'FashionWomen' => 'Women',
            'ForeignBooks' => 'English Books',
            'GiftCards' => 'Gift Cards',
            'GroceryAndGourmetFood' => 'Food & Beverage',
            'HealthPersonalCare' => 'Health & Personal Care',
            'Hobbies' => 'Hobby',
            'HomeAndKitchen' => 'Kitchen & Housewares',
            'Industrial' => 'Industrial & Scientific',
            'Jewelry' => 'Jewelry',
            'KindleStore' => 'Kindle Store',
            'MobileApps' => 'Apps & Games',
            'MoviesAndTV' => 'Movies & TV',
            'Music' => 'Music',
            'MusicalInstruments' => 'Musical Instruments',
            'OfficeProducts' => 'Stationery and Office Products',
            'PetSupplies' => 'Pet Supplies',
            'Shoes' => 'Shoes & Bags',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports',
            'ToolsAndHomeImprovement' => 'DIY, Tools & Garden',
            'Toys' => 'Toys',
            'VideoGames' => 'Computer & Video Games',
            'Watches' => 'Watches',
        ),
        'mx' => array(
            'All' => 'Todos los departamentos',
            'Automotive' => 'Auto',
            'Baby' => 'Bebé',
            'Books' => 'Libros',
            'Electronics' => 'Electrónicos',
            'Fashion' => 'Ropa, Zapatos y Accesorios',
            'FashionBaby' => 'Ropa, Zapatos y Accesorios Bebé',
            'FashionBoys' => 'Ropa, Zapatos y Accesorios Niños',
            'FashionGirls' => 'Ropa, Zapatos y Accesorios Niñas',
            'FashionMen' => 'Ropa, Zapatos y Accesorios Niñas',
            'FashionWomen' => 'Ropa, Zapatos y Accesorios Mujeres',
            'GroceryAndGourmetFood' => 'Alimentos y Bebidas',
            'Handmade' => 'Productos Handmade',
            'HealthPersonalCare' => 'Salud, Belleza y Cuidado Personal',
            'HomeAndKitchen' => 'Hogar y Cocina',
            'IndustrialAndScientific' => 'Industria y ciencia',
            'KindleStore' => 'Tienda Kindle',
            'MoviesAndTV' => 'Películas y Series de TV',
            'Music' => 'Música',
            'MusicalInstruments' => 'Instrumentos musicales',
            'OfficeProducts' => 'Oficina y Papelería',
            'PetSupplies' => 'Mascotas',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Deportes y Aire Libre',
            'ToolsAndHomeImprovement' => 'Herramientas y Mejoras del Hogar',
            'ToysAndGames' => 'Juegos y juguetes',
            'VideoGames' => 'Videojuegos',
            'Watches' => 'Relojes',
        ),
        'nl' => array(
            'All' => 'Alle afdelingen',
            'Automotive' => 'Auto en motor',
            'Baby' => 'Babyproducten',
            'Beauty' => 'Beauty en persoonlijke verzorging',
            'Books' => 'Boeken',
            'Electronics' => 'Elektronica',
            'EverythingElse' => 'Overig',
            'Fashion' => 'Kleding, schoenen en sieraden',
            'GardenAndOutdoor' => 'Tuin, terras en gazon',
            'GiftCards' => 'Cadeaubonnen',
            'GroceryAndGourmetFood' => 'Levensmiddelen',
            'HealthPersonalCare' => 'Gezondheid en persoonlijke verzorging',
            'HomeAndKitchen' => 'Wonen en keuken',
            'Industrial' => 'Zakelijk, industrie en wetenschap',
            'KindleStore' => 'Kindle Store',
            'MoviesAndTV' => 'Films en tv',
            'Music' => 'Cd\'s en lp\'s',
            'MusicalInstruments' => 'Muziekinstrumenten',
            'OfficeProducts' => 'Kantoorproducten',
            'PetSupplies' => 'Huisdierbenodigdheden',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sport en outdoor',
            'ToolsAndHomeImprovement' => 'Klussen en gereedschap',
            'ToysAndGames' => 'Speelgoed en spellen',
            'VideoGames' => 'Videogames',
        ),
        'sa' => array(
            'All' => 'All Categories',
            'ArtsAndCrafts' => 'Arts, Crafts & Sewing',
            'Automotive' => 'Automotive Parts & Accessories',
            'Baby' => 'Baby',
            'Beauty' => 'Beauty & Personal Care',
            'Books' => 'Books',
            'Computers' => 'Computer & Accessories',
            'Electronics' => 'Electronics',
            'Fashion' => 'Clothing, Shoes & Jewelry',
            'GardenAndOutdoor' => 'Home & Garden',
            'GiftCards' => 'Gift Cards',
            'GroceryAndGourmetFood' => 'Grocery & Gourmet Food',
            'HealthPersonalCare' => 'Health, Household & Baby Care',
            'HomeAndKitchen' => 'Kitchen & Dining',
            'Industrial' => 'Industrial & Scientific',
            'KindleStore' => 'Kindle Store',
            'Miscellaneous' => 'Everything Else',
            'MoviesAndTV' => 'MoviesAndTV',
            'Music' => 'CDs & Vinyl',
            'MusicalInstruments ' => 'Musical Instruments',
            'OfficeProducts' => 'Office Productsd',
            'PetSupplies' => 'Pet Supplies',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports',
            'ToolsAndHomeImprovement' => 'Tools & Home Improvement',
            'ToysAndGames' => 'Toys & Games',
            'VideoGames' => 'Video Games',
        ),
        'sg' => array(
            'All' => 'All Departments',
            'Automotive' => 'Automotive',
            'Baby' => 'Baby',
            'Beauty' => 'Beauty & Personal Care',
            'Computers' => 'Computers',
            'Electronics' => 'Electronics',
            'GroceryAndGourmetFood' => 'Grocery',
            'HealthPersonalCare' => 'HealthPersonalCare',
            'HomeAndKitchen' => 'Home, Kitchen & Dining',
            'OfficeProducts' => 'Office Products',
            'PetSupplies' => 'Pet Supplies',
            'SportsAndOutdoors' => 'Sports & Outdoors',
            'ToolsAndHomeImprovement' => 'Tools & Home Improvement',
            'ToysAndGames' => 'Toys & Games',
            'VideoGames' => 'Video Games',
        ),
        'es' => array(
            'All' => 'Todos los departamentos',
            'Apparel' => 'Ropa y accesorios',
            'Appliances' => 'Appliances',
            'Automotive' => 'Coche y moto',
            'Baby' => 'Bebé',
            'Beauty' => 'Belleza',
            'Books' => 'Libros',
            'Computers' => 'Informática',
            'DigitalMusic' => 'Música Digital',
            'Electronics' => 'Electrónica',
            'EverythingElse' => 'Otros Productos',
            'Fashion' => 'Moda',
            'ForeignBooks' => 'Libros en idiomas extranjeros',
            'GardenAndOutdoor' => 'Jardín',
            'GiftCards' => 'Cheques regalo',
            'GroceryAndGourmetFood' => 'Alimentación y bebidas',
            'Handmade' => 'Handmade',
            'HealthPersonalCare' => 'Salud y cuidado personal',
            'HomeAndKitchen' => 'Hogar y cocina',
            'Industrial' => 'Industria y ciencia',
            'Jewelry' => 'Joyería',
            'KindleStore' => 'Tienda Kindle',
            'Lighting' => 'Iluminación',
            'Luggage' => 'Equipaje',
            'MobileApps' => 'Appstore para Android',
            'MoviesAndTV' => 'Películas y TV',
            'Music' => 'Música: CDs y vinilos',
            'MusicalInstruments ' => 'Instrumentos musicales',
            'OfficeProducts' => 'Oficina y papelería',
            'PetSupplies' => 'Productos para mascotas',
            'Shoes' => 'Zapatos y complementos',
            'Software' => 'Softwares',
            'SportsAndOutdoors' => 'Deportes y aire libre',
            'ToolsAndHomeImprovement' => 'Bricolaje y herramientas',
            'ToysAndGames' => 'Juguetes y juegos',
            'Vehicles' => 'Coche - renting',
            'VideoGames' => 'Videojuegos',
            'Watches' => 'Relojes',
        ),
        'com.tr' => array(
            'All' => 'Tüm Kategoriler',
            'Baby' => 'Bebek',
            'Books' => 'Kitaplar',
            'Computers' => 'Bilgisayarlar',
            'Electronics' => 'Elektronik',
            'EverythingElse' => 'Diğer Her Şey',
            'Fashion' => 'Moda',
            'HomeAndKitchen' => 'Ev ve Mutfak',
            'OfficeProducts' => 'Ofis Ürünleri',
            'SportsAndOutdoors' => 'Spor',
            'ToolsAndHomeImprovement' => 'Yapı Market',
            'ToysAndGames' => 'Oyuncaklar ve Oyunlar',
            'VideoGames' => 'PC ve Video Oyunları',
        ),
        'ae' => array(
            'All' => 'All Departments',
            'Appliances' => 'Appliances',
            'ArtsAndCrafts' => 'Arts, Crafts & Sewing',
            'Automotive' => 'Automotive Parts & Accessories',
            'Baby' => 'Baby',
            'Beauty ' => 'Beauty & Personal Care',
            'Books' => 'Books',
            'Computers' => 'Computers',
            'Electronics' => 'Electronics',
            'EverythingElse' => 'Everything Else',
            'Fashion' => 'Clothing, Shoes & Jewelry',
            'GardenAndOutdoor' => 'Home & Garden',
            'GroceryAndGourmetFood' => 'Grocery & Gourmet Food',
            'HealthPersonalCare' => 'Health, Household & Baby Care',
            'HomeAndKitchen' => 'Home & Kitchen',
            'Industrial' => 'Industrial & Scientific',
            'Lighting' => 'Lighting',
            'MusicalInstruments' => 'Musical Instruments',
            'OfficeProducts' => 'Office Products',
            'PetSupplies' => 'Pet Supplies',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports',
            'ToolsAndHomeImprovement' => 'Tools & Home Improvement',
            'ToysAndGames' => 'Toys & Games',
            'VideoGames' => 'Video Games',
        ),
        'co.uk' => array(
            'All' => 'All Departments',
            'AmazonVideo' => 'Amazon Video',
            'Apparel' => 'Clothing',
            'Appliances' => 'Large Appliances',
            'Automotive' => 'Car & Motorbike',
            'Baby' => 'Baby',
            'Beauty' => 'Beauty',
            'Books' => 'Books',
            'Classical' => 'Classical Music',
            'Computers' => 'Computers & Accessories',
            'DigitalMusic' => 'Digital Music',
            'Electronics' => 'Electronics & Photo',
            'EverythingElse' => 'Everything Else',
            'Fashion' => 'Fashion',
            'GardenAndOutdoor' => 'Garden & Outdoors',
            'GiftCards' => 'Gift Cards',
            'GroceryAndGourmetFood' => 'Grocery',
            'Handmade' => 'Handmade',
            'HealthPersonalCare' => 'Health & Personal Care',
            'HomeAndKitchen' => 'Home & Kitchen',
            'Industrial' => 'Industrial & Scientific',
            'Jewelry' => 'Industrial & Scientific',
            'KindleStore' => 'Kindle Store',
            'Luggage' => 'Luggage',
            'LuxuryBeauty' => 'Luxury Beauty',
            'MobileApps' => 'Apps & Games',
            'MoviesAndTV' => 'DVD & Blu-ray',
            'Music' => 'CDs & Vinyl',
            'MusicalInstruments' => 'Musical Instruments & DJ',
            'OfficeProducts' => 'Stationery & Office SuppliesJ',
            'PetSupplies' => 'Pet Supplies',
            'Shoes' => 'Shoes & Bags',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports & Outdoors',
            'ToolsAndHomeImprovement' => 'DIY & Tools',
            'ToysAndGames' => 'Toys & Games',
            'VHS' => 'VHS',
            'VideoGames' => 'PC & Video Games',
            'Watches' => 'Watches',
        ),
        'com' => array(
            'All' => 'All Departments',
            'AmazonVideo' => 'Prime Video',
            'Apparel' => 'Clothing & Accessories',
            'Appliances' => 'Appliances',
            'ArtsAndCrafts' => 'Arts, Crafts & Sewing',
            'Automotive' => 'Automotive Parts & Accessories',
            'Baby' => 'Baby',
            'Beauty' => 'Beauty & Personal Care',
            'Books' => 'Books',
            'Classical' => 'Classical',
            'Collectibles' => 'Collectibles & Fine Art',
            'Computers' => 'Computers',
            'DigitalMusic' => 'Digital Music',
            'DigitalEducationalResources' => 'Digital Educational Resources',
            'Electronics' => 'Electronics',
            'EverythingElse' => 'Everything Else',
            'Fashion' => 'Clothing, Shoes & Jewelry',
            'FashionBaby' => 'Clothing, Shoes & Jewelry Baby',
            'FashionBoys' => 'Clothing, Shoes & Jewelry Boys',
            'FashionGirls' => 'Clothing, Shoes & Jewelry Girls',
            'FashionMen' => 'Clothing, Shoes & Jewelry Men',
            'FashionWomen' => 'Clothing, Shoes & Jewelry Women',
            'GardenAndOutdoor' => 'Garden & Outdoor',
            'GiftCards' => 'Gift Cards',
            'GroceryAndGourmetFood' => 'Grocery & Gourmet Food',
            'Handmade' => 'Handmade',
            'HealthPersonalCare' => 'Health, Household & Baby Care',
            'HomeAndKitchen' => 'Home & Kitchen',
            'Industrial' => 'Industrial & Scientific',
            'Jewelry' => 'Jewelry',
            'KindleStore' => 'Kindle Store',
            'LocalServices' => 'Home & Business Services',
            'Luggage' => 'Luggage & Travel Gear',
            'LuxuryBeauty' => 'Luxury Beauty',
            'Magazines  ' => 'Magazine Subscriptions',
            'MobileAndAccessories' => 'Cell Phones & Accessories',
            'MobileApps' => 'Apps & Gamess',
            'MoviesAndTV' => 'Movies & TV',
            'Music' => 'CDs & Vinyl',
            'MusicalInstruments' => 'Musical Instruments',
            'OfficeProducts' => 'Office Products',
            'PetSupplies' => 'Pet Supplies',
            'Photo' => 'Camera & Photo',
            'Shoes' => 'Shoes',
            'Software' => 'Software',
            'SportsAndOutdoors' => 'Sports & Outdoors',
            'ToolsAndHomeImprovement' => 'Tools & Home Improvement',
            'ToysAndGames' => 'Toys & Games',
            'VHS' => 'VHS',
            'VideoGames' => 'Video Games',
            'Watches' => 'Watches',
        ),
    );
    return $cat;
}
/**
 * Add products search
 */
function wca_add_products_search_count()
{
    $count = get_option('wca_products_search_count');
    $count = $count + 1;
    update_option('wca_products_search_count', $count);
}
/**
 * WooCommerce plugin missing notices.
 */
function ams_woocommerce_missing()
{
    $massing_text = esc_html__('Affiliate Management System - WooCommerce Amazon requires WooCommerce to be installed and active. You can download', 'ams-wc-amazon');
    $translators_text = sprintf(
        '<div class="error"><p><strong>%s <a href="https://wordpress.org/plugins/woocommerce/" target="_blank">%s</a> here.</strong></p></div>',
        esc_html($massing_text),
        esc_html__('WooCommerce', 'ams-wc-amazon')
    );
    echo wp_kses_post($translators_text);
}
/**
 * License not activation notices
 */
function ams_plugin_license_active_massage()
{
    $text = esc_html__('Affiliate Management System - WooCommerce Amazon plugin license not activated Please activate the plugin\'s license', 'ams-wc-amazon');
    $contain = sprintf('<div class="error"><p><strong>%s</strong></p></div>', esc_html($text));
    echo wp_kses_post($contain);
}
/**
 * License status check
 */
function ams_plugin_license_status()
{
    $status = get_option('ams_activated_status');
    if (strtolower($status) === strtolower('success')) {
        return true;
    } else {
        return false;
    }
}
/**
 *
 */
if (!function_exists('ams_clean')) {
    function ams_clean($var)
    {
        if (is_array($var)) {
            return array_map('ams_clean', $var);
        } else {
            return is_scalar($var) ? sanitize_text_field($var) : $var;
        }
    }
}
/**
 * Create a product variation for a defined variable product ID.
 *
 * @since 3.0.0
 * @param int   $product_id | Post ID of the product parent variable product.
 * @param array $variation_data | The data to insert in the product.
 */
function create_product_variation($product_id, $variation_data)
{
    // Get the Variable product object (parent)
    $product = wc_get_product($product_id);
    $variation_post = array(
        'post_title' => $product->get_name(),
        'post_name' => 'product-' . $product_id . '-variation',
        'post_status' => 'publish',
        'post_parent' => $product_id,
        'post_type' => 'product_variation',
        'guid' => $product->get_permalink(),
    );
    // Creating the product variation
    $variation_id = wp_insert_post($variation_post);
    // Get an instance of the WC_Product_Variation object
    $variation = new WC_Product_Variation($variation_id);
    // Iterating through the variations attributes
    foreach ($variation_data['attributes'] as $attribute => $term_name) {
        $taxonomy = 'pa_' . $attribute; // The attribute taxonomy
        // If taxonomy doesn't exists we create it (Thanks to Carl F. Corneil)
        if (!taxonomy_exists($taxonomy)) {
            register_taxonomy(
                $taxonomy,
                'product_variation',
                array(
                    'hierarchical' => false,
                    'label' => ucfirst($attribute),
                    'query_var' => true,
                    'rewrite' => array('slug' => sanitize_title($attribute)), // The base slug
                )
            );
        }
        // Check if the Term name exist and if not we create it.
        if (!term_exists($term_name, $taxonomy)) {
            wp_insert_term($term_name, $taxonomy);
        }
        // Create the term
        $term_slug = get_term_by('name', $term_name, $taxonomy)->slug; // Get the term slug
        // Get the post Terms names from the parent variable product.
        $post_term_names = wp_get_post_terms($product_id, $taxonomy, array('fields' => 'names'));
        // Check if the post term exist and if not we set it in the parent variable product.
        if (!in_array($term_name, $post_term_names)) {
            wp_set_post_terms($product_id, $term_name, $taxonomy, true);
        }
        // Set/save the attribute data in the product variation
        update_post_meta($variation_id, 'attribute_' . $taxonomy, $term_slug);
    }
    ## Set/save all other data
    // SKU
    if (!empty($variation_data['sku'])) {
        $variation->set_sku($variation_data['sku']);
    }
    // Prices
    if (empty($variation_data['sale_price'])) {
        $variation->set_price($variation_data['regular_price']);
    } else {
        $variation->set_price($variation_data['sale_price']);
        $variation->set_sale_price($variation_data['sale_price']);
    }
    $variation->set_regular_price($variation_data['regular_price']);
    // Stock
    if (!empty($variation_data['stock_qty'])) {
        $variation->set_stock_quantity($variation_data['stock_qty']);
        $variation->set_manage_stock(true);
        $variation->set_stock_status('');
    } else {
        $variation->set_manage_stock(false);
    }
    $variation->set_weight(''); // weight (reseting)
    $variation->save(); // Save the data
}
/**
 * Amazon product availability check
 */
add_action('wp_ajax_ams_product_availability', 'ams_product_availability');
function ams_product_availability()
{
    try {
        global $wpdb;
        $product_tags_cron = get_option('product_tags_cron');
        $product_variants_cron = get_option('product_variants_cron');
        $product_sku_cron = get_option('product_sku_cron');
        $product_price_cron = get_option('product_price_cron');
        $product_out_of_stock_cron = get_option('product_out_of_stock_cron');
        $product_description_cron = get_option('product_description_cron');
        $product_category_cron = get_option('product_category_cron');
        if ($_POST['data'] != '') {
            $id_asin = $_POST['data'];
        } else {
            $asins = ams_get_all_products_info();
            $id_asin = array_combine($asins['id'], $asins['asin']);
            $products_url = [];
            foreach ($asins['product_id'] as $key => $value) {
                $products_url[$key] = $value['url'];
            }
        }
        foreach ($id_asin as $id => $asin) {
            if (isset($_POST['product_url']) && !empty($_POST['product_url'])) {
                $url = $_POST['product_url'];
            } else if (isset($product_url) && isset($product_url[$id]) && !empty($product_url[$id])) {
                $url = $product_url[$id];
            } else {
                $url = sprintf('https://www.amazon.%s/dp/%s', get_option('ams_amazon_country'), $asin);
            }
            if (!class_exists('simple_html_dom')) {
                require_once __DIR__ . '/Admin/lib/simplehtmldom/simple_html_dom.php';
            }
            $product_import = new \Amazon\Affiliate\Admin\ProductsSearchWithoutApi();
            $product_url = sanitize_text_field( $url );
            //$impPro = new ImportProducts;
            $user_agent = $product_import->user_agent();
            $options = array(
                'http' => array(
                    'method' => "GET",
                    'header' => "Accept-language: en\r\n" .
                        $user_agent
                )
            );
            // code run wait
            sleep( rand( 1, 5 ) );
            $context = stream_context_create( $options );
            // wp_remote_get() not working properly so I'm forced to use it
            $response_body = $page = file_get_contents( esc_url_raw( $url ), false, $context );
            if(!empty($response_body)) {
                $html = new \simple_html_dom();
                $html->load($response_body);
                $product_status = 'instock';
                if ($html->find('#outOfStock .a-color-price', 0)) {
                    $product_status = 'outofstock';
                }
                $pricing = $product_import->fetchPriceFromHtml($html);
                $amount = $pricing['amount'];
                $regular_price = $pricing['regular_price'];
                $title = $html->find('#productTitle');
                $title = $title[0]->innertext;
                $content = $product_import->fetchContentFromHtml($html);

                if ($product_description_cron) {
                    wp_update_post(array(
                        'ID' => $id,
                        'post_title' => stripslashes(sanitize_text_field($title)),
                        'post_content' => $content,
                    ));

                    if($product_category_cron) {
                        $product_category = $product_import->syncAndGetCategory($html);
                    }
                    
                    // Check remote amazon images.
                    if ('1' === get_option('product_image_cron')) {
                        // Set product feature image.

                        $product_import->delete_product_images($id);
                        $gallery = $product_import->fetchImagesFromHtml($html);
                        $image = $gallery[0];
                        unset($gallery[0]);
                        $product_import->attach_product_thumbnail($id, $image, 0);
                        foreach ($gallery as $image) {
                            $product_import->attach_product_thumbnail($id, $image, 1);
                        }
                    }
                    if(!empty($product_category) && $product_category_cron) {
                        wp_set_object_terms($id, $product_category, 'product_cat');
                    }
                }
                if ($product_sku_cron) {
                    update_post_meta($id, '_sku', $asin);
                }
                if ($product_out_of_stock_cron) {
                    update_post_meta($id, '_stock_status', $product_status);
                }
                if ($product_price_cron) {
                    if ($amount) {
                        update_post_meta($id, '_price', $amount);
                    }
                    if ($regular_price) {
                        update_post_meta($id, '_regular_price', $regular_price);
                    }
                    if ($amount) {
                        update_post_meta($id, '_sale_price', $amount);
                    }
                }
                
                update_post_meta( $_POST['prod_id'], 'ams_last_cron_update',date('Y-m-d H:i:s'));
                update_post_meta( $_POST['prod_id'], 'ams_last_cron_status',1);
                echo '<div class="alert alert-success text-left" role="alert"> ' . esc_html__( 'Success, '.$title.' has been updated', 'ams-wc-amazon' ).'</div>';

                wc_delete_product_transients($id);
            } else {
                update_post_meta( $_POST['prod_id'], 'ams_last_cron_update',date('Y-m-d H:i:s'));
                update_post_meta( $_POST['prod_id'], 'ams_last_cron_status',0);
                echo '<div class="alert alert-danger text-left" role="alert">Something went wrong, '.$url.' has not updated!';
            }
        }
    } catch (\Throwable $th) {
        echo '<div class="alert alert-danger text-left" role="alert">Error: '.$th->getMessage().'</div>';
        update_post_meta( $_POST['prod_id'], 'ams_last_cron_update',date('Y-m-d H:i:s'));
        update_post_meta( $_POST['prod_id'], 'ams_last_cron_status',1);
    }
    wp_die();
}
add_action('ams_product_availability', 'ams_product_availability');

add_filter( 'manage_edit-product_columns', 'wootix_show_product_order', 15 ) ;
function wootix_show_product_order( $columns ){
    $columns['cron_run_status'] =  __( 'Cron Status', 'ams-wc-amazon' );
    return $columns;
}
add_action( 'manage_product_posts_custom_column', 'ExtraCronColumn', 10, 2 );
function ExtraCronColumn( $column, $postid ) {
    if ( $column == 'cron_run_status' ) {
        $date = get_post_meta( $postid, 'ams_last_cron_update', true);
        if (!empty($date)) {
            $status = get_post_meta( $postid, 'ams_last_cron_status', true);
            $html = '<div class="status-'.$status.'">';
            $html .= ($status == 1 ? 'Updated' : 'Not Updated');
            $html .= '<br>'.date('Y/m/d \a\t h:i a',strtotime($date));
            $html .= '</div>';
            echo $html;
        }else{
            echo 'Not Started';
        }
    }
}
function checkExistProduct($sku)
{
    $the_query = new WP_Query($args);
    // The Loop
    $return = false;
    if ($the_query->have_posts()) {
        while ($the_query->have_posts()) {
            $the_query->the_post();
            $post_id = get_the_ID();
            $_sku = get_post_meta($post_id, "_sku", true);
            if ($_sku == $sku) {
                $return = true;
                break;
            }
        }
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    return $return;
}
// add_action('admin_footer', 'ams_admin_add_js');
// function ams_admin_add_js($data) {
//     echo '<script>
//     </script>';
// }
add_action('wp_ajax_ams_get_currency_by_country', 'ams_get_currency_by_country');
function ams_get_currency_by_country() {
    $data = array(
        'AFN' => array( 'AF' ),
        'ALL' => array( 'AL' ),
        'DZD' => array( 'DZ' ),
        'USD' => array( 'AS', 'IO', 'GU', 'MH', 'FM', 'MP', 'PW', 'PR', 'TC', 'US', 'UM', 'VI', 'US'),
        'EUR' => array( 'AD', 'AT', 'BE', 'CY', 'EE', 'FI', 'FR', 'GF', 'TF', 'DE', 'GR', 'GP', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'MQ', 'YT', 'MC', 'ME', 'NL', 'PT', 'RE', 'PM', 'SM', 'SK', 'SI', 'ES' ),
        'AOA' => array( 'AO' ),
        'XCD' => array( 'AI', 'AQ', 'AG', 'DM', 'GD', 'MS', 'KN', 'LC', 'VC' ),
        'ARS' => array( 'AR' ),
        'AMD' => array( 'AM' ),
        'AWG' => array( 'AW' ),
        'AUD' => array( 'AU', 'CX', 'CC', 'HM', 'KI', 'NR', 'NF', 'TV' ),
        'AZN' => array( 'AZ' ),
        'BSD' => array( 'BS' ),
        'BHD' => array( 'BH' ),
        'BDT' => array( 'BD' ),
        'BBD' => array( 'BB' ),
        'BYR' => array( 'BY' ),
        'BZD' => array( 'BZ' ),
        'XOF' => array( 'BJ', 'BF', 'ML', 'NE', 'SN', 'TG' ),
        'BMD' => array( 'BM' ),
        'BTN' => array( 'BT' ),
        'BOB' => array( 'BO' ),
        'BAM' => array( 'BA' ),
        'BWP' => array( 'BW' ),
        'NOK' => array( 'BV', 'NO', 'SJ' ),
        'BRL' => array( 'BR' ),
        'BND' => array( 'BN' ),
        'BGN' => array( 'BG' ),
        'BIF' => array( 'BI' ),
        'KHR' => array( 'KH' ),
        'XAF' => array( 'CM', 'CF', 'TD', 'CG', 'GQ', 'GA' ),
        'CAD' => array( 'CA' ),
        'CVE' => array( 'CV' ),
        'KYD' => array( 'KY' ),
        'CLP' => array( 'CL' ),
        'CNY' => array( 'CN' ),
        'HKD' => array( 'HK' ),
        'COP' => array( 'CO' ),
        'KMF' => array( 'KM' ),
        'CDF' => array( 'CD' ),
        'NZD' => array( 'CK', 'NZ', 'NU', 'PN', 'TK' ),
        'CRC' => array( 'CR' ),
        'HRK' => array( 'HR' ),
        'CUP' => array( 'CU' ),
        'CZK' => array( 'CZ' ),
        'DKK' => array( 'DK', 'FO', 'GL' ),
        'DJF' => array( 'DJ' ),
        'DOP' => array( 'DO' ),
        'ECS' => array( 'EC' ),
        'EGP' => array( 'EG' ),
        'SVC' => array( 'SV' ),
        'ERN' => array( 'ER' ),
        'ETB' => array( 'ET' ),
        'FKP' => array( 'FK' ),
        'FJD' => array( 'FJ' ),
        'GMD' => array( 'GM' ),
        'GEL' => array( 'GE' ),
        'GHS' => array( 'GH' ),
        'GIP' => array( 'GI' ),
        'QTQ' => array( 'GT' ),
        'GGP' => array( 'GG' ),
        'GNF' => array( 'GN' ),
        'GWP' => array( 'GW' ),
        'GYD' => array( 'GY' ),
        'HTG' => array( 'HT' ),
        'HNL' => array( 'HN' ),
        'HUF' => array( 'HU' ),
        'ISK' => array( 'IS' ),
        'INR' => array( 'IN' ),
        'IDR' => array( 'ID' ),
        'IRR' => array( 'IR' ),
        'IQD' => array( 'IQ' ),
        'GBP' => array( 'IM', 'JE', 'GS', 'GB', 'UK' ),
        'ILS' => array( 'IL' ),
        'JMD' => array( 'JM' ),
        'JPY' => array( 'JP' ),
        'JOD' => array( 'JO' ),
        'KZT' => array( 'KZ' ),
        'KES' => array( 'KE' ),
        'KPW' => array( 'KP' ),
        'KRW' => array( 'KR' ),
        'KWD' => array( 'KW' ),
        'KGS' => array( 'KG' ),
        'LAK' => array( 'LA' ),
        'LBP' => array( 'LB' ),
        'LSL' => array( 'LS' ),
        'LRD' => array( 'LR' ),
        'LYD' => array( 'LY' ),
        'CHF' => array( 'LI', 'CH' ),
        'MKD' => array( 'MK' ),
        'MGF' => array( 'MG' ),
        'MWK' => array( 'MW' ),
        'MYR' => array( 'MY' ),
        'MVR' => array( 'MV' ),
        'MRO' => array( 'MR' ),
        'MUR' => array( 'MU' ),
        'MXN' => array( 'MX' ),
        'MDL' => array( 'MD' ),
        'MNT' => array( 'MN' ),
        'MAD' => array( 'MA', 'EH' ),
        'MZN' => array( 'MZ' ),
        'MMK' => array( 'MM' ),
        'NAD' => array( 'NA' ),
        'NPR' => array( 'NP' ),
        'ANG' => array( 'AN' ),
        'XPF' => array( 'NC', 'WF' ),
        'NIO' => array( 'NI' ),
        'NGN' => array( 'NG' ),
        'OMR' => array( 'OM' ),
        'PKR' => array( 'PK' ),
        'PAB' => array( 'PA' ),
        'PGK' => array( 'PG' ),
        'PYG' => array( 'PY' ),
        'PEN' => array( 'PE' ),
        'PHP' => array( 'PH' ),
        'PLN' => array( 'PL' ),
        'QAR' => array( 'QA' ),
        'RON' => array( 'RO' ),
        'RUB' => array( 'RU' ),
        'RWF' => array( 'RW' ),
        'SHP' => array( 'SH' ),
        'WST' => array( 'WS' ),
        'STD' => array( 'ST' ),
        'SAR' => array( 'SA' ),
        'RSD' => array( 'RS' ),
        'SCR' => array( 'SC' ),
        'SLL' => array( 'SL' ),
        'SGD' => array( 'SG' ),
        'SBD' => array( 'SB' ),
        'SOS' => array( 'SO' ),
        'ZAR' => array( 'ZA' ),
        'SSP' => array( 'SS' ),
        'LKR' => array( 'LK' ),
        'SDG' => array( 'SD' ),
        'SRD' => array( 'SR' ),
        'SZL' => array( 'SZ' ),
        'SEK' => array( 'SE' ),
        'SYP' => array( 'SY' ),
        'TWD' => array( 'TW' ),
        'TJS' => array( 'TJ' ),
        'TZS' => array( 'TZ' ),
        'THB' => array( 'TH' ),
        'TOP' => array( 'TO' ),
        'TTD' => array( 'TT' ),
        'TND' => array( 'TN' ),
        'TRY' => array( 'TR' ),
        'TMT' => array( 'TM' ),
        'UGX' => array( 'UG' ),
        'UAH' => array( 'UA' ),
        'AED' => array( 'AE' ),
        'UYU' => array( 'UY' ),
        'UZS' => array( 'UZ' ),
        'VUV' => array( 'VU' ),
        'VEF' => array( 'VE' ),
        'VND' => array( 'VN' ),
        'YER' => array( 'YE' ),
        'ZMW' => array( 'ZM' ),
        'ZWD' => array( 'ZW' ),
    );
    $selectedCountry = $_POST['country'];
    $result = ['status' => false];
    if($selectedCountry == 'com') {
        $result = ['status' => true, 'value' => 'USD'];
    } else {
        foreach ($data as $key => $value) {
            if(in_array(strtoupper($selectedCountry), $value)) {
                $result = ['status' => true, 'value' => $key];
                break;
            }
        }
    }
    echo json_encode($result);
    wp_die();    
}