Solution for Custom Pin/Marker per Store/Category
-
I’ve seen a few threads in here about this and figured I’d offer my solution. I’ve contacted WP Store Locator Support directly and asked if they could put this solution into the plugin. NOTE: this requires the use of filters and directly modifying some plugin code.
First add the wpsl_meta_box_fields and wpsl_frontend_meta_fields filters to your child theme. Documentation for both here https://wpstorelocator.co/document/wpsl_meta_box_fields/ and here https://wpstorelocator.co/document/wpsl_frontend_meta_fields/.
add_filter('wpsl_meta_box_fields', 'custom_meta_box_fields'); function custom_meta_box_fields($meta_fields) { $meta_fields[__( 'Additional Information', 'wpsl' )] = array( 'phone' => array( 'label' => __( 'Tel', 'wpsl' ) ), 'fax' => array( 'label' => __( 'Fax', 'wpsl' ) ), 'email' => array( 'label' => __( 'Email', 'wpsl' ) ), 'url' => array( 'label' => __( 'Url', 'wpsl' ) ), 'alternate_marker_url' => array( 'label' => __( 'Alternate Marker Url', 'wpsl' ) ) ); return $meta_fields; } add_filter('wpsl_frontend_meta_fields', 'custom_frontend_meta_fields'); function custom_frontend_meta_fields($store_fields) { $store_fields['wpsl_alternate_marker_url'] = array( 'name' => 'alternate_marker_url', 'type' => 'url' ); return $store_fields; }
Now in Edit Store > Additional Information you will have another field “Alternate Marker Url” available. Put the absolute url of the custom pin/marker here.
Now we need to modify a little plugin code directly. We need to make it load the non minified wpsl-gmap.js script (you can minify after if you like). In wp-store-locator/frontend/class-frontend.php find the following (should be line 1664 in the latest version):
wp_enqueue_script( 'wpsl-js', WPSL_URL . 'js/wpsl-gmap'. $min .'.js', array( 'jquery' ), WPSL_VERSION_NUM, true );
Change this to:
wp_enqueue_script( 'wpsl-js', WPSL_URL . 'js/wpsl-gmap.js', array( 'jquery' ), WPSL_VERSION_NUM, true );
And finally in wp-store-locator/js/wpsl-gmap.js we need to make it set the marker url to the url specified if it was set. Find the addMarker function and add the following if block before mapIcon is initialized:
if(infoWindowData.alternate_marker_url) { url = infoWindowData.alternate_marker_url; }
Here’s the section with the block added:
... if ( storeId === 0 ) { infoWindowData = { store: wpslLabels.startPoint }; url = markerSettings.url + wpslSettings.startMarker; } else { url = markerSettings.url + wpslSettings.storeMarker; } if(infoWindowData.alternate_marker_url) { url = infoWindowData.alternate_marker_url; } mapIcon = { url: url, scaledSize: new google.maps.Size( Number( markerSettings.scaledSize[0] ), Number( markerSettings.scaledSize[1] ) ), //retina format origin: new google.maps.Point( Number( markerSettings.origin[0] ), Number( markerSettings.origin[1] ) ), anchor: new google.maps.Point( Number( markerSettings.anchor[0] ), Number( markerSettings.anchor[1] ) ) }; ...
Hope this helps ??
- The topic ‘Solution for Custom Pin/Marker per Store/Category’ is closed to new replies.