Param Veer
Param Veer

Reputation: 786

Custom list of states countries in Woocommerce

I am trying to make a custom list of countries . I know how to make it for states . I have used

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

function custom_woocommerce_states( $states ) {
  $states['IN'] = array(
    'PB' => 'Punjab'
  );

  return $states;
}

For making it for states . But how to make a custom list of countries ?

Upvotes: 1

Views: 2369

Answers (2)

Rahul S
Rahul S

Reputation: 643

You can paste this in your theme functions.php file

/* Add a new country to countries list */
function woo_add_my_country( $country ) {
  $country["AE-DU"] = 'Dubai';  
    return $country; 
}
add_filter( 'woocommerce_countries', 'woo_add_my_country', 10, 1 );

Is this what you mean?

Upvotes: 0

Rohil_PHPBeginner
Rohil_PHPBeginner

Reputation: 6080

Is this what you want ?

add_filter('woocommerce_countries','custom_country', 10, 1);

function custom_country($mycountry){
    $mycountry = array(
        'AF' => __( 'Afghanistan', 'woocommerce' ),
        'IN' => __( 'India', 'woocommerce' )
    );
    return $mycountry;
}

Upvotes: 4

Related Questions