There is a list of all states and cities in html code. Actually I do not need states and cities.
I can remove them by adding this code to the functions.php
add_filter( 'woocommerce_states', function( $states ){
unset( $states['AF'] );
unset( $states['AL'] );
unset( $states['AO'] );
unset( $states['AR'] );
// AND SO ON
return $states;
}, 999);
But if I want to remove them all with code, I get an error:
add_filter( 'woocommerce_states', function( $states ){
unset( $states );
return $states;
}, 999);
Warning: array_merge(): Expected parameter 1 to be an array, null given in /public_html/wp-content/plugins/woocommerce/includes/class-wc-frontend-scripts.php on line 580
Is listing all the countries the only way to remove them from the html code?
2
Answers
Try by creating an empty array
I know there is already an accepted answer, but this could easily be resolved with one line, since
__return_empty_array
already does what you want.