Last active
November 9, 2022 10:38
-
-
Save JarrydLong/0596fb730d485aaf5b1906575c515146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This recipe will geocode the custom billing fields we've created during checkout. | |
* | |
* 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 mypmpromm_checkout_override(){ | |
//Remove this hook otherwise we'll geocode the billing address instead | |
remove_action( 'pmpro_after_checkout', 'pmpromm_after_checkout', 10, 2 ); | |
} | |
add_action( 'init', 'mypmpromm_checkout_override' ); | |
function mypmpromm_custom_billing_fields_checkout( $user_id, $morder ){ | |
//Requires PMPro Membrship Maps and PMPro Shipping Add On Active | |
if( !function_exists( 'pmpromm_geocode_address' ) ){ | |
return; | |
} | |
$scity = get_user_meta( $user_id, "pmpro_bcity", true ); | |
$scountry = get_user_meta( $user_id, "pmpro_bcountry", true ); | |
if( !empty( $scity ) || !empty( $scountry ) ){ | |
$member_address = array( | |
'street' => '', | |
'city' => $scity, | |
'state' => $scountry, | |
'zip' => '' | |
); | |
$coordinates = pmpromm_geocode_address( $member_address ); | |
if( is_array( $coordinates ) ){ | |
if( !empty( $coordinates['lat'] ) && !empty( $coordinates['lng'] ) ){ | |
update_user_meta( $user_id, 'pmpro_lat', $coordinates['lat'] ); | |
update_user_meta( $user_id, 'pmpro_lng', $coordinates['lng'] ); | |
} | |
} | |
} | |
} | |
add_action( 'pmpro_after_checkout', 'mypmpromm_custom_billing_fields_checkout', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment