Skip to content

Instantly share code, notes, and snippets.

@JarrydLong
Last active August 4, 2023 13:38
Show Gist options
  • Save JarrydLong/d5fad10c3674fc5c6ac1ae587135fc32 to your computer and use it in GitHub Desktop.
Save JarrydLong/d5fad10c3674fc5c6ac1ae587135fc32 to your computer and use it in GitHub Desktop.
<?php
/**
* This recipe will use custom billing fields and geocode them instead of default
* fields during the checkout process.
*
* Check for the $_REQUEST variable first before checking for the stored user meta.
*
* 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_custom_address_fields( $member_address, $user_id, $morder ){
$member_address = array(
'street' => ( !empty( $_REQUEST['street_name'] ) ) ? $_REQUEST['street_name'] : get_user_meta( $user_id, 'street_name', true ),
'city' => ( !empty( $_REQUEST['city_name'] ) ) ? $_REQUEST['city_name'] : get_user_meta( $user_id, 'city_name', true ),
'zip' => ( !empty( $_REQUEST['zip_code'] ) ) ? $_REQUEST['zip_code'] : get_user_meta( $user_id, 'zip_code', true ),
'country' => ( !empty( $_REQUEST['country'] ) ) ? $_REQUEST['country'] : get_user_meta( $user_id, 'country', true )
);
return $member_address;
}
add_filter( 'pmpromm_member_address_after_checkout', 'mypmpromm_custom_address_fields', 10, 3 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "How to Geocode Any Address Fields During Checkout" at Paid Memberships Pro here: https://www.paidmembershipspro.com/how-to-geocode-address-fields-during-checkout/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment