-
-
Save strangerstudios/b341f51c4afaf1d4444b to your computer and use it in GitHub Desktop.
| /* | |
| 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'); |
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
}
?>
Hi,
how do I set payments fields as not required on pmpro ?
did you manage to resolve that @serieseyw ? I am looking for similar solution
same here, how to make fields not required?
this is not working anymore. how to disable mandatory fields on checkout?
i tried several things its not working
/**
-
PMPro: Entfernt Pflichtfeld-Fehler für State und Phone im Checkout
-
Greift nach der internen Validierung
*/
add_action( 'pmpro_checkout_preheader', function() {
global $pmpro_msg, $pmpro_msgt;if ( empty( $pmpro_msg ) ) {
return;
}// Messages können String oder Array sein
if ( is_array( $pmpro_msg ) ) {
foreach ( $pmpro_msg as $key => $msg ) {
if (
stripos( $msg, 'state' ) !== false ||
stripos( $msg, 'phone' ) !== false
) {
unset( $pmpro_msg[ $key ] );
}
}// Wenn keine Fehler mehr da sind → Status zurücksetzen if ( empty( $pmpro_msg ) ) { $pmpro_msgt = false; }} else {
// Fallback bei String
if (
stripos( $pmpro_msg, 'state' ) !== false ||
stripos( $pmpro_msg, 'phone' ) !== false
) {
$pmpro_msg = false;
$pmpro_msgt = false;
}
}
});
@cremigerhonig This is still a valid hook and available in core. There may be another plugin requiring the fields running after this one.
You can try loading this snippet as late as possible to see if this helps:
add_action('pmpro_required_billing_fields', 'my_pmpro_required_billing_fields', 99);
For anyone needing official support with this snippet and debugging, please open a premium support at www.paidmembershipspro.com/support
Any suggestions for this to apply to all payment types?