Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break link between billing addresses and map pin location #76

Open
dparker1005 opened this issue Dec 20, 2023 · 2 comments
Open

Break link between billing addresses and map pin location #76

dparker1005 opened this issue Dec 20, 2023 · 2 comments

Comments

@dparker1005
Copy link
Member

Currently, each user's map location is based on their most recently used billing address. In situations where users have orders for multiple levels which may be using different payment methods, this may mean that a single user may have their location jump back and forth between billing addresses as new payments are made.

Instead, we should give users a different setting to choose their map pin location instead of trying to "detect" it. Not only does this make the plugin more compatible with MMPU, but it also allows users to set their pin location as somewhere other than their billing address. For example, if the map was showing company locations, the company location may not always be the same as the billing address used to purchase the membership.

In summary, the suggestion here is to track map pin location separately from billing addresses.

@zaczacariah
Copy link

I agree, this is quite crucial!

@zaczacariah
Copy link

I've come up with a work around for anyone in the meantime.

First step, create a some User Fields. I've done this based on the following article: https://www.paidmembershipspro.com/types-of-addresses/

Essentially you create a user field section and add the following fields:
Field Label Field Name (meta_key) Field Type
Address 1 physical_address1 text
Address 2 physical_address2 text
City physical_city text
State physical_state text
Zip Code physical_zip_code text
Country physical_country text

Then you can add this little snippet I did to your functions.php child theme file.

`
function update_lat_lng_from_physical_address( $user_id ) {

// Retrieve physical address fields
$physical_address = array(
    'street' => ( !empty( $_REQUEST['physical_address1'] ) ) ? $_REQUEST['physical_address1'] : get_user_meta( $user_id, 'physical_address1', true ),
    'city' => ( !empty( $_REQUEST['physical_suburb'] ) ) ? $_REQUEST['physical_suburb'] : get_user_meta( $user_id, 'physical_suburb', true ),
    'state' => ( !empty( $_REQUEST['physical_state'] ) ) ? $_REQUEST['physical_state'] : get_user_meta( $user_id, 'physical_state', true ),
    'zip' => ( !empty( $_REQUEST['physical_post_code'] ) ) ? $_REQUEST['physical_post_code'] : get_user_meta( $user_id, 'physical_post_code', true ),
    'country' => ( !empty( $_REQUEST['physical_country'] ) ) ? $_REQUEST['physical_country'] : get_user_meta( $user_id, 'physical_country', true )
);



// If any of the physical address fields are empty, bail.
if ( empty( $physical_address['street'] ) || empty( $physical_address['city'] ) || empty( $physical_address['zip'] ) || empty( $physical_address['country'] ) ) {
    return;
}

// Log existing coordinates before updating
$existing_lat = get_user_meta( $user_id, 'pmpro_lat', true );
$existing_lng = get_user_meta( $user_id, 'pmpro_lng', true );


// Geocode the physical address
$coordinates = pmpromm_geocode_address( $physical_address );

// Update user meta with latitude and longitude
if ( is_array( $coordinates ) && !empty( $coordinates['lat'] ) && !empty( $coordinates['lng'] ) ) {
    update_user_meta( $user_id, 'pmpro_lat', $coordinates['lat'] );
    update_user_meta( $user_id, 'pmpro_lng', $coordinates['lng'] );

    // Log new coordinates after updating
    $new_lat = $coordinates['lat'];
    $new_lng = $coordinates['lng'];
  
}

}

add_action( 'pmpro_personal_options_update', 'update_lat_lng_from_physical_address' );
add_action( 'personal_options_update', 'update_lat_lng_from_physical_address' );
add_action( 'edit_user_profile_update', 'update_lat_lng_from_physical_address' );
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants