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

您可以将其粘贴到主题函数.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 );

这就是你的意思吗?