Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimwhite/57736424725fd8b52d46bb973fc6ba52 to your computer and use it in GitHub Desktop.
Save kimwhite/57736424725fd8b52d46bb973fc6ba52 to your computer and use it in GitHub Desktop.
Make some billing fields optional
<?php
/**
* Remove the bstate baddress2 requirement from billing fields generated by PMPro or Address for Free Levels then hide them with CSS
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_remove_bstate_required( $pmpro_required_billing_fields ){
//remove field ID's from array to make fields required
$remove_field = array('bstate,baddress2');
//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', 'my_pmpro_remove_bstate_required', 50 );
// Hide state form field by adding CSS to the page head.
add_action( 'wp_head', 'wp_head_hide_billing_state_field' );
function wp_head_hide_billing_state_field() {
global $pmpro_pages;
if ( empty( $pmpro_pages ) || ( ! is_page( $pmpro_pages['checkout'] ) && ! is_page( $pmpro_pages['billing'] ) ) ) {
return;
}
?>
<style>
div.pmpro_checkout-field-bstate {
display: none;
}
div.pmpro_checkout-field-baddress2 {
display: none;
}
</style>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment