G
G
Genri_Rus2019-12-10 19:29:00
WordPress
Genri_Rus, 2019-12-10 19:29:00

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

There is this code:
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 ) . ' &mdash; ' . ( $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.
        }
      }
    }
  }

Can I somehow add my list of countries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@coderiter, 2019-12-11
_

Well, in the search for the first link. Tyk .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question