Created
August 7, 2020 17:48
-
-
Save gausam/04e4b02eb239bd94e68a4718de2c85dc to your computer and use it in GitHub Desktop.
Add billing fields, with dropdown for country, to the Membership Profile page
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 adds billing fields to the Membership Profile page. | |
* | |
* It is intended for use with the Register Helper Add On: | |
* https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/ | |
* | |
* 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/ | |
* | |
* Based on https://gist.github.com/andrewlimaza/e17a82948542e0a036446ee15b1bf014 | |
*/ | |
function add_billing_fields_to_add_member_profile() { | |
// we will use PMPro's list of countries | |
global $pmpro_countries; | |
//check for register helper | |
if ( ! function_exists( "pmprorh_add_registration_field" ) ) { | |
return; | |
} | |
//define the fields | |
$fields = array(); | |
$fields[] = new PMProRH_Field("pmpro_baddress1", "text", array("label"=>"Billing Address 1", "size"=>40, "profile"=>true, "required"=>false, "addmember" => true)); | |
$fields[] = new PMProRH_Field("pmpro_baddress2", "text", array("label"=>"Billing Address 2", "size"=>40, "profile"=>true, "required"=>false, "addmember" => true)); | |
$fields[] = new PMProRH_Field("pmpro_bcity", "text", array("label"=>"Billing City", "size"=>40, "profile"=>true, "required"=>false, "addmember" => true)); | |
$fields[] = new PMProRH_Field("pmpro_bstate", "text", array("label"=>"Billing State", "size"=>10, "profile"=>true, "required"=>false, "addmember" => true)); | |
$fields[] = new PMProRH_Field("pmpro_bzipcode", "text", array("label"=>"Billing Postal Code", "size"=>10, "profile"=>true, "required"=>false, "addmember" => true)); | |
// prepare countries for dropdown | |
$options = array(); | |
foreach($pmpro_countries as $abbr => $country) { | |
$options[$abbr] = $country; | |
} | |
$fields[] = new PMProRH_Field( | |
"pmpro_bcountry", | |
"select", | |
array( | |
"label" => "Billing Country", | |
"profile" => true, | |
"required" => false, | |
"addmember" => true, | |
"options" => $options, | |
) | |
); | |
$fields[] = new PMProRH_Field("pmpro_bphone", "text", array("label"=>"Billing Phone", "size"=>40, "profile"=>true, "required"=>false, "addmember" => true)); | |
//add the fields into a new checkout_boxes are of the checkout page | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field("profile", $field); | |
} | |
} | |
add_action( "init", "add_billing_fields_to_add_member_profile" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment