Forked from strangerstudios/wp_head_hide_billing_fields.php
Last active
November 22, 2023 00:10
-
-
Save CrandellWS/9a9c82ea5b99cd531e0ec74eb39409b6 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.
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
add_action('pmpro_checkout_before_submit_button', 'my_pmp_jquery'); | |
function my_pmp_jquery() { | |
global $current_user; | |
get_currentuserinfo(); | |
if ($current_user->user_login) { | |
//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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment