Answer the question
In order to leave comments, you need to log in
How to add your list of countries on the checkout page?
Let's say I have my own list of countries and regions: https://codepen.io/Korotenko/pen/JjoGXVQ
There is a class
plugins/woocommerce/includes/class-wc-countries.php
public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
if ( $this->countries ) {
foreach ( $this->countries as $key => $value ) {
$states = $this->get_states( $key );
if ( $states ) {
echo '<optgroup label="' . esc_attr( $value ) . '">';
foreach ( $states as $state_key => $state_value ) {
echo '<option value="' . esc_attr( $key ) . ':' . esc_attr( $state_key ) . '"';
if ( $selected_country === $key && $selected_state === $state_key ) {
echo ' selected="selected"';
}
echo '>' . esc_html( $value ) . ' — ' . ( $escape ? esc_js( $state_value ) : $state_value ) . '</option>'; // WPCS: XSS ok.
}
echo '</optgroup>';
} else {
echo '<option';
if ( $selected_country === $key && '*' === $selected_state ) {
echo ' selected="selected"';
}
echo ' value="' . esc_attr( $key ) . '">' . ( $escape ? esc_js( $value ) : $value ) . '</option>'; // WPCS: XSS ok.
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question