Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Oct 21, 2014

Any suggestions for this to apply to all payment types?

@andrewteg

This comment has been minimized.

Copy link

commented Feb 16, 2017

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
}
?>
@CrandellWS

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.