WCPBC_Country_Selector

WCPBC_Country_Selector class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wcpbc-country-selector.php  
  1. class WCPBC_Country_Selector { 
  2.  
  3. /** 
  4. * Hook actions and shortcodes 
  5. */ 
  6. public static function init() {  
  7.  
  8. add_shortcode( 'wcpbc_country_selector', array( __CLASS__ , 'shortcode_country_selector' ) ); 
  9.  
  10. add_action( 'wcpbc_manual_country_selector', array( __CLASS__ , 'output_country_selector' ) ); 
  11.  
  12. /** 
  13. * Return installed countries 
  14. * @return array 
  15. */ 
  16. private static function get_countries() { 
  17.  
  18. $all_countries = WC()->countries->get_countries();  
  19. $base_country = wc_get_base_location();  
  20.  
  21. $countries[ $base_country['country'] ] = $all_countries[$base_country['country']]; 
  22.  
  23. foreach ( WCPBC()->get_regions() as $region ) { 
  24.  
  25. foreach ( $region['countries'] as $country ) { 
  26.  
  27. if ( ! array_key_exists( $country, $countries ) ) { 
  28. $countries[ $country ] = $all_countries[$country];  
  29. }  
  30.  
  31. asort( $countries ); 
  32.  
  33. $other_country = key( array_diff_key($all_countries, $countries ) ); 
  34.  
  35. $countries[$other_country] = apply_filters( 'wcpbc_other_countries_text', __( 'Other countries' ) ); 
  36.  
  37. return $countries; 
  38.  
  39. /** 
  40. * Return manual country select form 
  41. */ 
  42. public static function shortcode_country_selector() {  
  43.  
  44. ob_start(); 
  45.  
  46. echo '<div class="wc-price-based-country">'; 
  47. wc_get_template('country-selector.php', array( 'countries' => self::get_countries(), 'selected_country' => wcpbc_get_woocommerce_country() ), 'woocommerce-product-price-based-on-countries/', WCPBC()->plugin_path() . '/templates/' ); 
  48. echo '</div>'; 
  49.  
  50. return ob_get_clean(); 
  51.  
  52. /** 
  53. * Output manual country select form 
  54. */ 
  55. public static function output_country_selector() { 
  56. echo self::shortcode_country_selector();