Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active October 9, 2023 11:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewlimaza/605a29ff9ee0701894e6e7bb90d10c95 to your computer and use it in GitHub Desktop.
Save andrewlimaza/605a29ff9ee0701894e6e7bb90d10c95 to your computer and use it in GitHub Desktop.
Make billing details optional for Paid Memberships Pro
<?php
//add lines 4-15 to your custom plugin or functions.php of your active theme
function pmpro_remove_bfields( $pmpro_required_billing_fields ){
//remove field ID's from array to make fields required
$remove_field = array('bfirstname', 'blastname', 'baddress1', 'bcity', 'bstate', 'bcountry', 'bzipcode', 'bphone', 'bemail', 'bconfirmemail');
//loop through the $remove_field array and unset each billing field to make it optional.
foreach($remove_field as $field){
unset($pmpro_required_billing_fields[$field]);
}
return $pmpro_required_billing_fields;
}
add_filter('pmpro_required_billing_fields', 'pmpro_remove_bfields');
@cremigerhonig
Copy link

Hi There,
I love your code and so far everything worked quite well. It´s excellent and easy to follow your structure.
But in this case, I am not able to get it working.

I am using Paid Memberships Pro - Address For Free Levels Add On to ask for the address (used for invoce plugin later on) on check out.

The problem is, I want to get rid of several billing fields like "state" "country" and "phone"
They just shouldn´t be displayed.

I already stopped them to be necessary by deleting some section in the "pmpro-address-for-free-level.php"

this worked well. BUT
I can´t get rid of them, I was searching for hours and nothing helped.
Can you please tell me some thoughts on this?

`/**

  • Make sure address fields are required
    */
    function pmproaffl_pmpro_required_billing_fields( $fields ) {
    global $bfirstname, $blastname, $baddress1, $bcity, $bstate, $bzipcode, $bcountry, $bphone, $bemail;

    $fields["bfirstname"] = $bfirstname;
    $fields["blastname"] = $blastname;
    $fields["baddress1"] = $baddress1;
    $fields["bcity"] = $bcity;
    $fields["bzipcode"] = $bzipcode;
    $fields["bemail"] = $bemail;
    $fields["bcountry"] = $bcountry;

    return $fields;`

@andrewlimaza
Copy link
Author

For the "Paid Memberships Pro - Address For Free Levels Add On", you may need to increase the priority of the code to be 50+

For example:

add_filter('pmpro_required_billing_fields', 'pmpro_remove_bfields', 50);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment