Woocommerce 中国家/地区的自定义列表

Custom list of states countries in Woocommerce

我正在尝试制作一个自定义的国家/地区列表。我知道如何为各州制作它。我用过

add_filter( 'woocommerce_states', 'custom_woocommerce_states' );

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

  return $states;
}

为各州制作它。但是如何制作自定义国家/地区列表?

这是你想要的吗?

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

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

您可以将其粘贴到您的主题 functions.php 文件中

/* 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 );

你是这个意思吗?