Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active November 22, 2023 00:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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_checkout-field-bstate {
display: none;
}
</style>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment