Build on the plugin’s data instead of shipping your own copy. These functions are part of the stable public API (VAFW_API_VERSION, currently 1).
Check that the plugin is there
if ( defined( 'VAFW_API_VERSION' ) ) {
// Safe to call vafw_*() functions.
}
// Or wait for it:
add_action( 'vafw_loaded', function ( $api_version ) {
// …
} );
Functions
| Function | Returns |
|---|---|
vafw_provinces() | Key → short name for all 34 provinces, e.g. 'HCM' => 'TP. Hồ Chí Minh' |
vafw_get_province( $key_or_code ) | code, key, name, short, type — or null |
vafw_wards( $province ) | Ward code → official name for one province |
vafw_get_ward( $code ) | code, name and its province — or null |
vafw_find_ward( $province, $text ) | The official ward for what someone typed: code and name, or null when none or ambiguous |
vafw_enqueue_picker() | Loads the ward picker on the current page (see Picker on any form) |
A province can be given by its key (HCM) or its official code (79).
Examples
Validate a ward from your own form
$ward = vafw_find_ward( 'HCM', 'ben thanh' );
// [ 'code' => '26743', 'name' => 'Phường Bến Thành' ]
if ( ! $ward ) {
// Ask the customer to choose a ward from the list.
}
Show an address saved as a code
$code = $order->get_meta( '_vafw_shipping_ward' );
$ward = vafw_get_ward( $code );
if ( $ward ) {
echo esc_html( $ward['name'] . ', ' . $ward['province']['short'] );
// Phường Bến Thành, TP. Hồ Chí Minh
}