Advertisement
palsushobhan

ticket-425178-country-MY-support-jvectormap.php

Feb 3rd, 2022
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter('wcfma_country_state_list', function($wcfma_country_state_list) {
  2.     if(!isset($wcfma_country_state_list['MY'])) {
  3.         $my_state_list = array(
  4.             'MY' => array(
  5.                 'label' => 'Malaysia',
  6.                 'state' => array(
  7.                     "MY-01" => "Johor",
  8.                     "MY-02" => "Kedah",
  9.                     "MY-03" => "Kelantan",
  10.                     "MY-04" => "Melaka",
  11.                     "MY-05" => "Negeri Sembilan",
  12.                     "MY-06" => "Pahang",
  13.                     "MY-07" => "Pulau Pinang",
  14.                     "MY-08" => "Perak",
  15.                     "MY-09" => "Perlis",
  16.                     "MY-10" => "Selangor",
  17.                     "MY-11" => "Terengganu",
  18.                     "MY-12" => "Sabah",
  19.                     "MY-13" => "Sarawak",
  20.                     "MY-14" => "Kuala Lumpur",
  21.                     "MY-15" => "Labuan",
  22.                     "MY-16" => "Putrajaya",
  23.                 ),
  24.             ),
  25.         );
  26.         return array_slice( $wcfma_country_state_list, 0, 1, true ) + $my_state_list + array_slice( $wcfma_country_state_list, 1, count( $wcfma_country_state_list ) - 1, true );
  27.     }
  28.     return $wcfma_country_state_list;
  29. });
  30.  
  31. add_action( 'wcfm_load_scripts', 'load_script_enhanced_region', 9 );
  32. add_action( 'after_wcfm_load_scripts', 'load_script_enhanced_region', 9 );
  33.  
  34. function load_script_enhanced_region($end_point) {
  35.     global $WCFM, $WCFMa;
  36.     remove_action( current_filter(), array($WCFMa->library, 'load_scripts') );
  37.     switch( $end_point ) {
  38.         case 'wcfm-dashboard':
  39.             if ( $is_wcfm_analytics_enable = is_wcfm_analytics() ) {
  40.                 if ( $wcfm_is_allow_analytics = apply_filters( 'wcfm_is_allow_analytics', true ) ) {
  41.                         load_jvectormap_lib();
  42.                         wp_enqueue_script( 'wcfma_analytics_js', $WCFMa->library->js_lib_url . 'wcfma-script-analytics-dashboard.js', array('jquery'), $WCFMa->version, true );
  43.                     }
  44.                 }
  45.         break;
  46.         case 'wcfm-analytics':
  47.             load_jvectormap_lib();
  48.             $WCFM->library->load_select2_lib();
  49.             $WCFM->library->load_chartjs_lib();
  50.             $WCFM->library->load_daterangepicker_lib();
  51.             wp_enqueue_script( 'wcfma_analytics_js', $WCFMa->library->js_lib_url . 'wcfma-script-analytics.js', array('jquery'), $WCFMa->version, true );
  52.             wp_enqueue_script( 'wcfma_analytics_dashboard_js', $WCFMa->library->js_lib_url . 'wcfma-script-analytics-dashboard.js', array('jquery'), $WCFMa->version, true );
  53.       break;
  54.      
  55.     }
  56. }
  57.  
  58. function load_jvectormap_lib(){
  59.     global $WCFMa;
  60.     wp_enqueue_script( 'jquery-jvectormap_js', $WCFMa->plugin_url . 'includes/jvectormap/jquery-jvectormap-2.0.3.min.js', array('jquery'), $WCFMa->version, true );
  61.     $user_id = apply_filters( 'wcfm_current_vendor_id', get_current_user_id() );
  62.     $wcfm_analytics_region = get_user_meta( $user_id, 'wcfm_analytics_region', true );
  63.     if( !$wcfm_analytics_region ) $wcfm_analytics_region = 'world';
  64.     $wcfm_analytics_region = strtolower( $wcfm_analytics_region );
  65.     $path = $WCFMa->plugin_url . 'includes/jvectormap/';
  66.     if($wcfm_analytics_region=='my') {
  67.         $path = get_stylesheet_directory_uri() . '/js/';
  68.     }
  69.     wp_enqueue_script( 'jquery-jvectormap-world_js', $path.$wcfm_analytics_region.'-mill.js', array('jquery', 'jquery-jvectormap_js'), $WCFMa->version, true );
  70.     wp_enqueue_style( 'wcfm_timepicker_css',  $WCFMa->plugin_url . 'includes/jvectormap/jquery-jvectormap-2.0.3.css', array(), $WCFMa->version );
  71. }
  72.  
  73. add_filter('get_wcfma_map_name_list', function($list) {
  74.     $list['my'] = 'my_regions';
  75.     return $list;
  76. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement