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 MaryOJob/a9f31336863b13905be87bea52635f3d to your computer and use it in GitHub Desktop.
Save MaryOJob/a9f31336863b13905be87bea52635f3d to your computer and use it in GitHub Desktop.
PMPro - Remove required * from some billing fields and then hide these fields with CSS
<?php // Do NOT copy this line
/*
* Remove required * from some billing fields and then hide these fields with CSS
* Add this to your PMPro Customization Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
add_action( 'pmpro_required_billing_fields', 'my_pmpro_required_billing_fields' );
function my_pmpro_required_billing_fields( $fields ) {
if ( is_array( $fields ) ) {
unset( $fields['blastname'] );
unset( $fields['baddress1'] );
unset( $fields['baddress2'] );
unset( $fields['bcity'] );
unset( $fields['bstate'] );
unset( $fields['bzipcode'] );
unset( $fields['bcountry'] );
}
return $fields;
}
// Hide state form field by adding CSS to the page head.
function my_pmpro_hide_billing_fields_css() {
global $pmpro_pages;
if ( empty( $pmpro_pages ) || ( ! is_page( $pmpro_pages['checkout'] ) && ! is_page( $pmpro_pages['billing'] ) ) ) {
return;
}
?>
<style>
div.pmpro_checkout-field-blastname,
div.pmpro_checkout-field-baddress1,
div.pmpro_checkout-field-baddress2,
div.pmpro_checkout-field-bcity,
div.pmpro_checkout-field-bstate,
div.pmpro_checkout-field-bzipcode,
div.pmpro_checkout-field-bcountry {
display: none;
}
</style>
<?php
}
add_action( 'wp_head', 'my_pmpro_hide_billing_fields_css' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment