Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active November 12, 2024 11:52
Show Gist options
  • Save ipokkel/e0f381cde0ab3fd13e7b69608e2dd7b1 to your computer and use it in GitHub Desktop.
Save ipokkel/e0f381cde0ab3fd13e7b69608e2dd7b1 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
/* Copy from below this line */
/*
Remove state from required billing fields and hide it the state field.
*/
// Unset state
function my_pmpro_required_billing_fields( $fields ) {
if ( is_array( $fields ) ) {
unset( $fields['bstate'] );
}
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_form_field.pmpro_form_field-bstate {
display: none;
}
</style>
<?php
}
@lagenceoueb
Copy link

lagenceoueb commented Nov 12, 2024

Hi @ipokkel

As you can see below,
I've modified the code that didn't work in my context, even though I'm on the checkout page (WP 6.6.2 / PMP 3.3.1).

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_form_field.pmpro_form_field-bstate {
		display: none;
		}
	</style>
	<?php
}

Feel free to use it if it's ok for you.
Thanks again for this code ;)
Regards,
Jm Silone

@ipokkel
Copy link
Author

ipokkel commented Nov 12, 2024

Thank you, @lagenceoueb, I've updated the CSS selector accordingly. :)

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