Advertisement
palsushobhan

WCFM Store Location Map

Mar 16th, 2025
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.31 KB | None | 0 0
  1. add_shortcode('wcfm_vendor_location', function($attr) {
  2.     global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post;
  3.        
  4.     $store_id = '';
  5.     if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); }
  6.    
  7.     if ( !$store_id && wcfm_is_store_page() ) {
  8.         $wcfm_store_url = wcfm_get_option( 'wcfm_store_url', 'store' );
  9.         $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
  10.         $store_id  = 0;
  11.         if ( !empty( $store_name ) ) {
  12.             $store_user = get_user_by( 'slug', $store_name );
  13.         }
  14.         $store_id           = $store_user->ID;
  15.     }
  16.    
  17.     if( !$store_id && is_product() ) {
  18.         $store_id = $post->post_author;
  19.     }
  20.    
  21.     if( !$store_id && is_single() && $post && is_object( $post ) && wcfm_is_vendor( $post->post_author ) ) {
  22.         $store_id = $post->post_author;
  23.     }
  24.    
  25.     if( !$store_id ) return;
  26.    
  27.     $is_store_offline = get_user_meta( $store_id, '_wcfm_store_offline', true );
  28.     if ( $is_store_offline ) {
  29.         return;
  30.     }
  31.    
  32.     $label = '';
  33.     if ( isset( $attr['label'] ) && !empty( $attr['label'] ) ) { $label = $attr['label']; }
  34.    
  35.     $icon = '';
  36.     if ( isset( $attr['icon'] ) && !empty( $attr['icon'] ) ) { $icon = $attr['icon']; }
  37.    
  38.     $store_user  = wcfmmp_get_store( $store_id );
  39.     $store_info  = $store_user->get_shop_info();
  40.    
  41.     $content = '<div class="wcfmmp_store_info wcfmmp_store_info_store_location">';
  42.    
  43.     if( $icon ) {
  44.         $content .= '<i style="display:inline-block" class="wcfmfa fa-' . $icon . ' wcfmmp_store_info_icon wcfmmp_store_info_iconl_store_location"></i>&nbsp&nbsp';
  45.     }
  46.    
  47.     if( $label ) {
  48.         $content .= '<span style="display:inline-block" class="wcfmmp_store_info_label wcfmmp_store_info_label_store_location">' . $label . '</span>:&nbsp';
  49.     }
  50.     $api_key = isset( $WCFMmp->wcfmmp_marketplace_options['wcfm_google_map_api'] ) ? $WCFMmp->wcfmmp_marketplace_options['wcfm_google_map_api'] : '';
  51.     $wcfm_map_lib = isset( $WCFMmp->wcfmmp_marketplace_options['wcfm_map_lib'] ) ? $WCFMmp->wcfmmp_marketplace_options['wcfm_map_lib'] : '';
  52.     if( !$wcfm_map_lib && $api_key ) { $wcfm_map_lib = 'google'; } elseif( !$wcfm_map_lib && !$api_key ) { $wcfm_map_lib = 'leaftlet'; }
  53.     $store_lat    = isset( $store_info['store_lat'] ) ? esc_attr( $store_info['store_lat'] ) : 0;
  54.     $store_lng    = isset( $store_info['store_lng'] ) ? esc_attr( $store_info['store_lng'] ) : 0;
  55.  
  56.     if ( ( ( ($wcfm_map_lib == 'google') && !empty( $api_key ) ) || ($wcfm_map_lib == 'leaflet') ) && !empty( $store_lat ) && !empty( $store_lng ) ) {
  57.         ob_start();
  58.         $WCFMmp->template->get_template( 'store/widgets/wcfmmp-view-store-location.php', array(
  59.                                                                                                         'store_user' => $store_user,
  60.                                                                                                         'store_info' => $store_info,
  61.                                                                                                         'store_lat'  => $store_lat,
  62.                                                                                                         'store_lng'  => $store_lng,
  63.                                                                                                         'map_id'     => 'wcfm_sold_by_widget_map_'.rand(10,100)
  64.                                                                                                         ) );
  65.         $content .=  ob_get_clean();
  66.        
  67.         if( !wcfmmp_is_store_page() ) {
  68.             wp_enqueue_style( 'wcfmmp_product_css',  $WCFMmp->library->css_lib_url . 'store/wcfmmp-style-product.css', array(), $WCFMmp->version );
  69.             wp_enqueue_script( 'wcfmmp_store_js', $WCFMmp->library->js_lib_url . 'store/wcfmmp-script-store.js', array('jquery' ), $WCFMmp->version, true );
  70.             $WCFMmp->library->load_map_lib();
  71.             // Default Map Location
  72.             $default_geolocation = isset( $WCFMmp->wcfmmp_marketplace_options['default_geolocation'] ) ? $WCFMmp->wcfmmp_marketplace_options['default_geolocation'] : array();
  73.             $default_lat         = isset( $default_geolocation['lat'] ) ? esc_attr( $default_geolocation['lat'] ) : apply_filters( 'wcfmmp_map_default_lat', 30.0599153 );
  74.             $default_lng         = isset( $default_geolocation['lng'] ) ? esc_attr( $default_geolocation['lng'] ) : apply_filters( 'wcfmmp_map_default_lng', 31.2620199 );
  75.             $default_zoom        = apply_filters( 'wcfmmp_map_default_zoom_level', 17 );
  76.             $store_icon          = apply_filters( 'wcfmmp_map_store_icon', esc_url($WCFMmp->plugin_url . 'assets/images/wcfmmp_map_icon.png'), 0, '' );
  77.             wp_localize_script( 'wcfmmp_store_js', 'wcfmmp_store_map_options', array( 'default_lat' => $default_lat, 'default_lng' => $default_lng, 'default_zoom' => absint( $default_zoom ), 'store_icon' => $store_icon, 'icon_width' => apply_filters( 'wcfmmp_map_icon_width', 40 ), 'icon_height' => apply_filters( 'wcfmmp_map_icon_height', 57 ), 'is_poi' => apply_filters( 'wcfmmp_is_allow_map_poi', true ), 'is_allow_scroll_zoom' => apply_filters( 'wcfmmp_is_allow_map_scroll_zoom', true ), 'is_rtl' => is_rtl() ) );
  78.         }
  79.     }
  80.     $content .= '</div>';
  81.     return $content;
  82. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement