Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode('wcfm_vendor_location', function($attr) {
- global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post;
- $store_id = '';
- if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); }
- if ( !$store_id && wcfm_is_store_page() ) {
- $wcfm_store_url = wcfm_get_option( 'wcfm_store_url', 'store' );
- $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );
- $store_id = 0;
- if ( !empty( $store_name ) ) {
- $store_user = get_user_by( 'slug', $store_name );
- }
- $store_id = $store_user->ID;
- }
- if( !$store_id && is_product() ) {
- $store_id = $post->post_author;
- }
- if( !$store_id && is_single() && $post && is_object( $post ) && wcfm_is_vendor( $post->post_author ) ) {
- $store_id = $post->post_author;
- }
- if( !$store_id ) return;
- $is_store_offline = get_user_meta( $store_id, '_wcfm_store_offline', true );
- if ( $is_store_offline ) {
- return;
- }
- $label = '';
- if ( isset( $attr['label'] ) && !empty( $attr['label'] ) ) { $label = $attr['label']; }
- $icon = '';
- if ( isset( $attr['icon'] ) && !empty( $attr['icon'] ) ) { $icon = $attr['icon']; }
- $store_user = wcfmmp_get_store( $store_id );
- $store_info = $store_user->get_shop_info();
- $content = '<div class="wcfmmp_store_info wcfmmp_store_info_store_location">';
- if( $icon ) {
- $content .= '<i style="display:inline-block" class="wcfmfa fa-' . $icon . ' wcfmmp_store_info_icon wcfmmp_store_info_iconl_store_location"></i>  ';
- }
- if( $label ) {
- $content .= '<span style="display:inline-block" class="wcfmmp_store_info_label wcfmmp_store_info_label_store_location">' . $label . '</span>: ';
- }
- $api_key = isset( $WCFMmp->wcfmmp_marketplace_options['wcfm_google_map_api'] ) ? $WCFMmp->wcfmmp_marketplace_options['wcfm_google_map_api'] : '';
- $wcfm_map_lib = isset( $WCFMmp->wcfmmp_marketplace_options['wcfm_map_lib'] ) ? $WCFMmp->wcfmmp_marketplace_options['wcfm_map_lib'] : '';
- if( !$wcfm_map_lib && $api_key ) { $wcfm_map_lib = 'google'; } elseif( !$wcfm_map_lib && !$api_key ) { $wcfm_map_lib = 'leaftlet'; }
- $store_lat = isset( $store_info['store_lat'] ) ? esc_attr( $store_info['store_lat'] ) : 0;
- $store_lng = isset( $store_info['store_lng'] ) ? esc_attr( $store_info['store_lng'] ) : 0;
- if ( ( ( ($wcfm_map_lib == 'google') && !empty( $api_key ) ) || ($wcfm_map_lib == 'leaflet') ) && !empty( $store_lat ) && !empty( $store_lng ) ) {
- ob_start();
- $WCFMmp->template->get_template( 'store/widgets/wcfmmp-view-store-location.php', array(
- 'store_user' => $store_user,
- 'store_info' => $store_info,
- 'store_lat' => $store_lat,
- 'store_lng' => $store_lng,
- 'map_id' => 'wcfm_sold_by_widget_map_'.rand(10,100)
- ) );
- $content .= ob_get_clean();
- if( !wcfmmp_is_store_page() ) {
- wp_enqueue_style( 'wcfmmp_product_css', $WCFMmp->library->css_lib_url . 'store/wcfmmp-style-product.css', array(), $WCFMmp->version );
- wp_enqueue_script( 'wcfmmp_store_js', $WCFMmp->library->js_lib_url . 'store/wcfmmp-script-store.js', array('jquery' ), $WCFMmp->version, true );
- $WCFMmp->library->load_map_lib();
- // Default Map Location
- $default_geolocation = isset( $WCFMmp->wcfmmp_marketplace_options['default_geolocation'] ) ? $WCFMmp->wcfmmp_marketplace_options['default_geolocation'] : array();
- $default_lat = isset( $default_geolocation['lat'] ) ? esc_attr( $default_geolocation['lat'] ) : apply_filters( 'wcfmmp_map_default_lat', 30.0599153 );
- $default_lng = isset( $default_geolocation['lng'] ) ? esc_attr( $default_geolocation['lng'] ) : apply_filters( 'wcfmmp_map_default_lng', 31.2620199 );
- $default_zoom = apply_filters( 'wcfmmp_map_default_zoom_level', 17 );
- $store_icon = apply_filters( 'wcfmmp_map_store_icon', esc_url($WCFMmp->plugin_url . 'assets/images/wcfmmp_map_icon.png'), 0, '' );
- 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() ) );
- }
- }
- $content .= '</div>';
- return $content;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement