Last active
November 12, 2024 11:52
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).
Feel free to use it if it's ok for you.
Thanks again for this code ;)
Regards,
Jm Silone