Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Paid Memberships Pro hooks to enable international addresses
<?php
/*
Add this code to your theme's functions.php file to update the checkout page to support international credit cards.
*/
/*
First we need to enable international addresses. We just use the pmpro_international_addresses hook and return true.
This will add a "countries" dropdown to the checkout page.
*/
function my_pmpro_international_addresses()
{
return true;
}
add_filter("pmpro_international_addresses", "my_pmpro_international_addresses");
/*
Change some of the billing fields to be not required to support international addresses that don't have a state, etc.
Default fields are: bfirstname, blastname, baddress1, bcity, bstate, bzipcode, bphone, bemail, bcountry, CardType, AccountNumber, ExpirationMonth, ExpirationYear, CVV
*/
function my_pmpro_required_billing_fields($fields)
{
//remove state and zip
unset($fields['bstate']);
unset($fields['bzipcode']);
return $fields;
}
add_filter("pmpro_required_billing_fields", "my_pmpro_required_billing_fields");
/*
Make the city, state, and zip/postal code fields show up on their own lines.
*/
function my_pmpro_longform_address()
{
return true;
}
add_filter("pmpro_longform_address", "my_pmpro_longform_address");
/*
(optional) Now we want to change the default country from US to say the United Kingdom (GB)
Use the 2-letter acronym.
*/
function my_pmpro_default_country($default)
{
return "GB";
}
//add_filter("pmpro_default_country", "my_pmpro_default_country");
/*
(optional) You may want to add/remove certain countries from the list. The pmpro_countries filter allows you to do this.
The array is formatted like array("US"=>"United States", "GB"=>"United Kingdom"); with the acronym as the key and the full
country name as the value.
*/
function my_pmpro_countries($countries)
{
//remove the US
unset($countries["US"]);
//add The Moon (LN short for Lunar?)
$countries["LN"] = "The Moon";
//You could also rebuild the array from scratch.
//$countries = array("CA" => "Canada", "US" => "United States", "GB" => "United Kingdom");
return $countries;
}
//add_filter("pmpro_countries", "my_pmpro_countries");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment