/**
 * Add custom fields to Paid Memberships Pro checkout page.
 * Must have PMPro & Register Helper Add On installed and activated to work.
 * Add this code to a PMPro Customizations Plugin or Code Snippets plugin.
 */

function pmpro_add_fields_to_checkout(){
	//don't break if Register Helper is not loaded
	if(!function_exists( 'pmprorh_add_registration_field' )) {
		return false;
	}
	
	$fields = array();
	
	$fields[] = new PMProRH_Field(
		'Phone',					// input name, will also be used as meta key
		'text',						// type of field
		array(
			'memberslistcsv' => true, //Add field to csv file on export.
			'addmember' => true, // Add field to Add Member (Add Member Admin should be activated.)
			'label'		=> 'Phone',		// custom field label
			'profile'	=> true,		// show in user profile
			'required'	=> true,		// make this field required
			'hint' => "Please enter your phone number. Don't forget to add your country code. (Example +961 03xxxxxx)",
			'html_attributes' => 'placeholder => hello'
		)
			);
	
	
	$fields[] = new PMProRH_Field(
		'City',					// input name, will also be used as meta key
		'text',						// type of field
		array(
			'memberslistcsv' => true, //Add field to csv file on export.
			'addmember' => true, // Add field to Add Member (Add Member Admin should be activated.)
			'profile' => true,
			'required' => true,
			'label'		=> 'City',	// custom field label
			'hint' => 'Please enter your city.',

		)
			);
	
	
	$fields[] = new PMProRH_Field(
		'State/Province',					// input name, will also be used as meta key
		'text',						// type of field
		array(
			'memberslistcsv' => true, //Add field to csv file on export.
			'addmember' => true, // Add field to Add Member (Add Member Admin should be activated.)
			'label'		=> 'State/Province',	// custom field label
			'required'	=> true,	// make this field required
			'profile'	=> true,	// show in user profile
			'hint' => 'Please enter your state/province.',
					)
	);

	$fields[] = new PMProRH_Field(
		'Address',					// input name, will also be used as meta key
		'text',						// type of field
		array(
			'memberslistcsv' => true, //Add field to csv file on export.
			'addmember' => true, // Add field to Add Member (Add Member Admin should be activated.)
			'label'		=> 'Address',	// custom field label
			'required'	=> true,	// make this field required
			'profile'	=> true,	// show in user profile
			'hint' => 'Please enter your full address.',

		)
			);
	$fields[] = new PMProRH_Field(
		'Country',					// input name, will also be used as meta key
		'select',						// type of field
		array(
			'memberslistcsv' => true, //Add field to csv file on export.
			'addmember' => true, // Add field to Add Member (Add Member Admin should be activated.)
			'label'		=> 'Country',	// custom field label
			'required'	=> false,	// make this field required
			'profile'	=> true,	// show in user profile
			'options' => array("Afganistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antigua & Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bonaire","Bosnia & Herzegovina","Botswana","Brazil","British Indian Ocean Ter","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Canary Islands","Cape Verde","Cayman Islands","Central African Republic","Chad","Channel Islands","Chile","China","Christmas Island","Cocos Island","Colombia","Comoros","Congo","Cook Islands","Costa Rica","Cote DIvoire","Croatia","Cuba","Curaco","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","East Timor","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Ter","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Great Britain","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala","Guinea","Guyana","Haiti","Hawaii","Honduras","Hong Kong","Hungary","Iceland","Indonesia","India","Iran","Iraq","Ireland","Isle of Man","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Korea North","Korea Sout","Kuwait","Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malaysia","Malawi","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mayotte","Mexico","Midway Islands","Moldova","Monaco","Mongolia","Montserrat","Morocco","Mozambique","Myanmar","Nambia","Nauru","Nepal","Netherland Antilles","Netherlands","Nevis","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Norway","Oman","Pakistan","Palau Island","Palestine","Panama","Papua New Guinea","Paraguay","Peru","Phillipines","Pitcairn Island","Poland","Portugal","Puerto Rico","Qatar","Republic of Montenegro","Republic of Serbia","Reunion","Romania","Russia","Rwanda","St Barthelemy","St Eustatius","St Helena","St Kitts-Nevis","St Lucia","St Maarten","St Pierre & Miquelon","St Vincent & Grenadines","Saipan","Samoa","Samoa American","San Marino","Sao Tome & Principe","Saudi Arabia","Senegal","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","Spain","Sri Lanka","Sudan","Suriname","Swaziland","Sweden","Switzerland","Syria","Tahiti","Taiwan","Tajikistan","Tanzania","Thailand","Togo","Tokelau","Tonga","Trinidad & Tobago","Tunisia","Turkey","Turkmenistan","Turks & Caicos Is","Tuvalu","Uganda","United Kingdom","Ukraine","United Arab Erimates","United States of America","Uraguay","Uzbekistan","Vanuatu","Vatican City State","Venezuela","Vietnam","Virgin Islands (Brit)","Virgin Islands (USA)","Wake Island","Wallis & Futana Is","Yemen","Zaire","Zambia","Zimbabwe")

));
		$fields[] = new PMProRH_Field(
		'Biography',					// input name, will also be used as meta key
		'textarea',						// type of field
		array(
			'memberslistcsv' => true, //Add field to csv file on export.
			'addmember' => true, // Add field to Add Member (Add Member Admin should be activated.)
			'label'		=> 'Biography',	// custom field label
			'required'	=> true,	// make this field required
			'profile'	=> true,	// show in user profile
			'hint' => 'Tell us more about yourself.'
		)
			);
		$fields[] = new PMProRH_Field(
		'fileUpload',					// input name, will also be used as meta key
		'file',						// type of field
		array(
			'memberslistcsv' => true, //Add field to csv file on export.
			'addmember' => true, // Add field to Add Member (Add Member Admin should be activated.)
			'label'		=> 'File Upload',	// custom field label
			'required'	=> true,	// make this field required
			'profile'	=> true,	// show in user profile
			'hint' => 'Kindly upload a picture of your official ID.',
			'accept' => "image/*"

		)
			);
		

	//add the fields to default forms
	foreach($fields as $field){
		pmprorh_add_registration_field(
			'checkout_boxes', // location on checkout page
			$field	// PMProRH_Field object
		);
	}
}
add_action( 'init', 'pmpro_add_fields_to_checkout' );