Forked from andrewlimaza/pmpro-bstate-optional.php
Last active
March 26, 2024 15:51
-
-
Save kimwhite/57736424725fd8b52d46bb973fc6ba52 to your computer and use it in GitHub Desktop.
Make some billing fields optional
This file contains 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 | |
/** | |
* Remove the bstate baddress2 requirement from billing fields generated by PMPro or Address for Free Levels then hide them with CSS | |
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_remove_bstate_required( $pmpro_required_billing_fields ){ | |
//remove field ID's from array to make fields required | |
$remove_field = array('bstate,baddress2'); | |
//loop through the $remove_field array and unset each billing field to make it optional. | |
foreach($remove_field as $field){ | |
unset($pmpro_required_billing_fields[$field]); | |
} | |
return $pmpro_required_billing_fields; | |
} | |
add_filter('pmpro_required_billing_fields', 'my_pmpro_remove_bstate_required', 50 ); | |
// 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; | |
} | |
div.pmpro_checkout-field-baddress2 { | |
display: none; | |
} | |
</style> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment