businessdad icon

How to add a custom list of states in WooCommerce

businessdad | PRO | 05/16/15 07:03:12 PM UTC | 0 ⭐ | 1114 👁️ | Never ⏰ | []
PHP |

870 B

|

None

|

0 👍

/

0 👎

/**
 * Adds the UAE emirates to the list of states available at checkout.
 *
 * Need a consultation? Find us on Codeable: https://bit.ly/codeable_discount
 *
 * @param array states The list of states passed by WooCommerce.
 * @return array The list of states, including the emirates for the UAE.
 * @author Aelia <[email protected]>
 */
add_filter('woocommerce_states', function($states) {
    // Note: the keys of the array may not be correct. I used arbitrary values,
    // to illustrate the concept
    $states['AE'] = array(
        'AD' => __('Abu Dhabi', 'your_text_domain'),
        'DB' => __('Dubai', 'your_text_domain'),
        'SH' => __('Sharjah', 'your_text_domain'),
        'AJ' => __('Ajman', 'your_text_domain'),
        'FJ' => __('Fujairah', 'your_text_domain'),
        'RS' => __('Ras al-Khaimah', 'your_text_domain'),
        'UM' => __('Umm al-Qaiwain', 'your_text_domain'),
    );
    return $states;
});

Comments