Custom list of states countries in Woocommerce

旧城冷巷雨未停 提交于 2019-12-19 11:53:09

问题


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 ?


回答1:


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;
}



回答2:


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?



来源:https://stackoverflow.com/questions/30999632/custom-list-of-states-countries-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!