Advertisement
palsushobhan

ticket-379782-new-country-support-jvectormap.php

Oct 22nd, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.09 KB | None | 0 0
  1. add_filter('wcfma_country_state_list', function($wcfma_country_state_list) {
  2.     if(!isset($wcfma_country_state_list['BG'])) {
  3.         $bulgaria_state_list = array(
  4.             'BG' => array(
  5.                 'label' => 'Bulgaria',
  6.                 'state' => array(
  7.                     'BG342' =>  "Sliven",
  8.                     'BG422' =>  "Haskovo",
  9.                     'BG222' =>  "Stara Zagora",
  10.                     'BG224' =>  "Pazardzhik",
  11.                     'BG421' =>  "Plovdiv",
  12.                     'BG225' =>  "Smolyan",
  13.                     'BG425' =>  "Kardzhali",
  14.                     'BG411' =>  "Sofia City",
  15.                     'BG412' =>  "Sofia",
  16.                     'BG414' =>  "Pernik",
  17.                     'BG124' =>  "Gabrovo",
  18.                     'BG122' =>  "Lovech",
  19.                     'BG314' =>  "Pleven",
  20.                     'BG321' =>  "Veliko Tarnovo",
  21.                     'BG112' =>  "Montana",
  22.                     'BG113' =>  "Vratsa",
  23.                     'BG215' =>  "Kyustendil",
  24.                     'BG311' =>  "Vidin",
  25.                     'BG231' =>  "Burgas",
  26.                     'BG233' =>  "Yambol",
  27.                     'BG324' =>  "Razgrad",
  28.                     'BG334' =>  "Targovishte",
  29.                     'BG133' =>  "Shumen",
  30.                     'BG332' =>  "Dobrich",
  31.                     'BG131' =>  "Varna",
  32.                     'BG136' =>  "Silistra",
  33.                     'BG323' =>  "Ruse",
  34.                     'BG413' =>  "Blagoevgrad",
  35.                 ),
  36.             ),
  37.         );
  38.         return array_slice( $wcfma_country_state_list, 0, 1, true ) + $bulgaria_state_list + array_slice( $wcfma_country_state_list, 1, count( $wcfma_country_state_list ) - 1, true );
  39.     }
  40.     return $wcfma_country_state_list;
  41. });
  42.  
  43. add_action( 'wcfm_load_scripts', 'load_script_enhanced_region', 9 );
  44. add_action( 'after_wcfm_load_scripts', 'load_script_enhanced_region', 9 );
  45.  
  46. function load_script_enhanced_region($end_point) {
  47.     global $WCFM, $WCFMa;
  48.     remove_action( current_filter(), array($WCFMa->library, 'load_scripts') );
  49.     switch( $end_point ) {
  50.         case 'wcfm-dashboard':
  51.             if ( $is_wcfm_analytics_enable = is_wcfm_analytics() ) {
  52.                 if ( $wcfm_is_allow_analytics = apply_filters( 'wcfm_is_allow_analytics', true ) ) {
  53.                         load_jvectormap_lib();
  54.                         wp_enqueue_script( 'wcfma_analytics_js', $WCFMa->library->js_lib_url . 'wcfma-script-analytics-dashboard.js', array('jquery'), $WCFMa->version, true );
  55.                     }
  56.                 }
  57.         break;
  58.         case 'wcfm-analytics':
  59.             load_jvectormap_lib();
  60.             $WCFM->library->load_select2_lib();
  61.             $WCFM->library->load_chartjs_lib();
  62.             $WCFM->library->load_daterangepicker_lib();
  63.             wp_enqueue_script( 'wcfma_analytics_js', $WCFMa->library->js_lib_url . 'wcfma-script-analytics.js', array('jquery'), $WCFMa->version, true );
  64.             wp_enqueue_script( 'wcfma_analytics_dashboard_js', $WCFMa->library->js_lib_url . 'wcfma-script-analytics-dashboard.js', array('jquery'), $WCFMa->version, true );
  65.       break;
  66.      
  67.     }
  68. }
  69.  
  70. function load_jvectormap_lib(){
  71.     global $WCFMa;
  72.     wp_enqueue_script( 'jquery-jvectormap_js', $WCFMa->plugin_url . 'includes/jvectormap/jquery-jvectormap-2.0.3.min.js', array('jquery'), $WCFMa->version, true );
  73.     $user_id = apply_filters( 'wcfm_current_vendor_id', get_current_user_id() );
  74.     $wcfm_analytics_region = get_user_meta( $user_id, 'wcfm_analytics_region', true );
  75.     if( !$wcfm_analytics_region ) $wcfm_analytics_region = 'world';
  76.     $wcfm_analytics_region = strtolower( $wcfm_analytics_region );
  77.     $path = $WCFMa->plugin_url . 'includes/jvectormap/';
  78.     if($wcfm_analytics_region=='bg') {
  79.         $path = get_stylesheet_directory_uri() . '/js/';
  80.     }
  81.     wp_enqueue_script( 'jquery-jvectormap-world_js', $path.$wcfm_analytics_region.'-mill.js', array('jquery', 'jquery-jvectormap_js'), $WCFMa->version, true );
  82.     wp_enqueue_style( 'wcfm_timepicker_css',  $WCFMa->plugin_url . 'includes/jvectormap/jquery-jvectormap-2.0.3.css', array(), $WCFMa->version );
  83. }
  84.  
  85. add_filter('get_wcfma_map_name_list', function($list) {
  86.     $list['bg'] = 'bg_regions';
  87.     return $list;
  88. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement