Are you using our Paid Memberships Pro Memberships Add On but need to change the default map starting point. The code recipe below will help you to override this starting point and select one more suited to your needs.

Overriding the Default Membership Map

About the Code Recipe

The Paid Memberships Pro Membership Maps Add On will by default take the location of the first marker on your map, and use that as the start location of your map.

If you’d like to set the default start location to one of your preference, you can make use of the code recipe below. This recipe will apply the same start location to all maps on your website. 


The Code Recipe

<?php
/**
* This recipe will override the default start location with a specific location.
* By default, we'll use the first marker on the map's location as the starting point
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function mypmromm_override_default_map_start( $coordinates, $map_id ){
$coordinates = array(
'lat' => -34.397,
'lng' => 150.644
);
return $coordinates;
}
add_filter( 'pmpromm_default_map_start', 'mypmromm_override_default_map_start', 10, 2 );
function mypmpromm_override_first_marker( $okay, $map_id ) {
return true;
}
add_filter( 'pmpromm_override_first_marker', 'mypmpromm_override_first_marker', 10, 2 );

Code Recipe Variation

You can also specify which map you’d like to override the start point on by using the following code recipe. The $ID variable references the ID attribute used in each map shortcode

<?php
/**
* This recipe will override the default start location of a specific map.
* By default, we'll use the first marker on the map's location as the starting point
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
//Override the homepage-map and use the coordinates set out in mypmromm_override_default_map_start
function mypmpromm_override_first_marker( $override, $ID ){
if( $ID == "homepage-map" ){
$override = true;
}
return $override;
}
add_filter( 'pmpromm_override_first_marker', 'mypmpromm_override_first_marker', 10, 2 );
//Using specific URLs
function mypmromm_override_default_map_start( $coordinates, $map_id ){
$coordinates = array(
'lat' => -34.397,
'lng' => 150.644
);
return $coordinates;
}
add_filter( 'pmpromm_default_map_start', 'mypmromm_override_default_map_start', 10, 2 );

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.


Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics


Was this article helpful?
YesNo