Address Regions (State/County)
If you want to filter the state/county options shown in the address field you can use this filter.
Filter Hook name: surecart_address_regions
This is a JavaScript filter and must be loaded through a script on the frontend.
You can use plugins such as Simple Custom CSS and JS, which allow you to easily add custom scripts.
For reference, see a screenshot demonstrating filter usage within the Simple Custom CSS and JS plugin: https://bsf.d.pr/i/XwsdWc
Filter Usage Example:
In the example below, we are adding two regions to the country of Taiwan..
wp.hooks.addFilter(
'surecart_address_regions', // Hook name.
'testnamespace', // Any custom namespace.
(regions, country) => {
if( 'TW' === country ) { // Check for the country code of which you want to update the regions.
regions.push( // Push custom regions you want in below format.
{
label: 'Test Region 1',
value: 'test-region-one',
},
{
label: 'Test Region 2',
value: 'test-region-two',
},
);
}
return regions;
}
);
This filter can be used to remove regions, translate region names, or otherwise modify the regions array as needed.
Note:
The regions array you return must be an array of objects. Each region object in the array should contain only the label and value key-value pairs.
Updated 10 days ago