Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created September 8, 2014 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save strangerstudios/b341f51c4afaf1d4444b to your computer and use it in GitHub Desktop.
Save strangerstudios/b341f51c4afaf1d4444b to your computer and use it in GitHub Desktop.
Hide Paid Memberships Pro billing address fields and make them optional. Meant to be used with the Braintree gateway.
/*
Hide billing address fields and make them optional.
Meant to be used with the Braintree Payments gateway.
*/
//css to hide the fields
function wp_head_hide_billing_fields()
{
global $post, $pmpro_pages;
if(empty($pmpro_pages) || (!is_page($pmpro_pages['checkout']) && !is_page($pmpro_pages['billing'])))
return;
?>
<style>
#pmpro_billing_address_fields {display: none;}
</style>
<?php
}
add_action('wp_head', 'wp_head_hide_billing_fields');
//make sure they aren't required
function my_pmpro_required_billing_fields($fields)
{
if(is_array($fields))
{
unset($fields['bfirstname']);
unset($fields['blastname']);
unset($fields['baddress1']);
unset($fields['baddress2']);
unset($fields['bcity']);
unset($fields['bstate']);
unset($fields['bzipcode']);
unset($fields['bcountry']);
unset($fields['bphone']);
}
return $fields;
}
add_action('pmpro_required_billing_fields', 'my_pmpro_required_billing_fields');
@robbie-berns
Copy link

Any suggestions for this to apply to all payment types?

@andrewteg
Copy link

Know this is old and some options have changed, but this still works for Stripe to at least make them not required. I do this to hide individual fields in Stripe if I need some but not all. I use jQuery which should be pretty standard across payment types:

<?php
add_action('pmpro_checkout_before_submit_button', 'my_pmp_jquery');
function my_pmp_jquery() {
	global $current_user;
	get_currentuserinfo();
	if (!$current_user->user_login) {
		//good spot check if you require registration before payment, otherwise remove IF statement
		exit('<meta http-equiv="refresh" content="0; url=/">'); //headers already sent by PMP so meta refresh to homepage
	}
	//script will hide billing fields and prefill name and email from WP account
	?>
	<script>
		jQuery( document ).ready(function($) {
			var fname = '<?php echo $current_user->user_firstname; ?>';
			var lname = '<?php echo $current_user->user_lastname; ?>';
			var user_email = '<?php echo $current_user->user_email; ?>';
			//console.log(user_email);
			$('#bfirstname').val(fname);
			$('#blastname').val(lname);
			$('#baddress1').parent().hide();
			$('#baddress2').parent().hide();
			$('#bcity').parent().hide();
			$('#bstate').parent().hide();
			$('#bzipcode').parent().hide();
			$('#bcountry').parent().hide();
			$('select[name=bcountry]').parent().hide(); //no id in some versions
			$('#bphone').parent().hide();
			$('#bemail').prop('disabled', 'true'); //disable changing email here if you know they are logged in
		}); //ready
	</script>
	<?php
}
?>

@serieseyw
Copy link

Hi,
how do I set payments fields as not required on pmpro ?

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