Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/059639d7d8f7278fb3124b713b78c0d3 to your computer and use it in GitHub Desktop.
Save kimwhite/059639d7d8f7278fb3124b713b78c0d3 to your computer and use it in GitHub Desktop.
PMPro - Remove state from required billing fields and hide it the state field.
<?php // do not copy this line.
/**
* Remove state and phone from required billing fields and hide it the state field.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Unset state and phone
function my_pmpro_required_billing_fields( $fields ) {
if ( is_array( $fields ) ) {
unset( $fields['bstate'] );
unset( $fields['bphone'] );
}
return $fields;
}
//run it later in the queue if necessary if other plugins or code sets fields required, e.g. change 50 to a higher number.
add_action( 'pmpro_required_billing_fields', 'my_pmpro_required_billing_fields', 50, 1 );
// 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,div.pmpro_checkout-field-bphone {
display: none;
}
</style>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment