Home / Attachments / modify woocommerce countries list
Duplicate Snippet

Embed Snippet on Your Site

modify woocommerce countries list

modifies Woocommerce built in country names to Armenian Regions disabling the rest

Code Preview
php
<?php
add_filter( 'woocommerce_countries', 'modify_woocommerce_country_names' );
function modify_woocommerce_country_names( $countries ) {
    // List of country codes to keep
    $allowed_countries = array(
        'ER', 'AO', 'DZ', 'AU', 'BD', 'BG', 'BJ', 'BO', 'BR', 'CA', 'CH'
    );
    
    // Loop through all countries and remove the ones that are not in the allowed list
    foreach ( $countries as $code => $name ) {
        if ( ! in_array( $code, $allowed_countries ) ) {
            unset( $countries[$code] );
        }
    }
    // Modify country names as per your list
    $countries['ER'] = 'Երևան';
    $countries['AO'] = 'Արագածոտն';
    $countries['DZ'] = 'Արարատ';
    $countries['AU'] = 'Արմավիր';
    $countries['BD'] = 'Գեղարքունիք';
    $countries['BG'] = 'Կոտայք';
    $countries['BJ'] = 'Լոռի';
    $countries['BO'] = 'Շիրակ';
    $countries['BR'] = 'Սյունիք';
    $countries['CA'] = 'Տավուշ';
    $countries['CH'] = 'Վայոց ձոր';
    // Return the modified countries array
    return $countries;
}

Comments

Add a Comment