Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created September 8, 2014 19:48
Show Gist options
  • Select an option

  • Save strangerstudios/b341f51c4afaf1d4444b to your computer and use it in GitHub Desktop.

Select an option

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');
@cremigerhonig
Copy link

same here, how to make fields not required?

@cremigerhonig
Copy link

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;
    }
    }
    });

@andrewlimaza
Copy link

@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);

@andrewlimaza
Copy link

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