Created
September 8, 2014 19:48
-
-
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.
This file contains hidden or 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
| /* | |
| 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'); |
@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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ] );
}
}
} else {
// Fallback bei String
if (
stripos( $pmpro_msg, 'state' ) !== false ||
stripos( $pmpro_msg, 'phone' ) !== false
) {
$pmpro_msg = false;
$pmpro_msgt = false;
}
}
});