Forked from andrewlimaza/pmpro-bstate-optional.php
Last active
October 2, 2024 13:35
-
-
Save kimwhite/57736424725fd8b52d46bb973fc6ba52 to your computer and use it in GitHub Desktop.
Make some billing fields optional
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 | |
/** | |
* Remove the some billing fields generated by PMPro or Address for Free Levels Add On | |
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_remove_billing_required( $pmpro_required_billing_fields ){ | |
// Correctly define the array of fields you want to remove | |
$remove_fields = array( 'baddress1','baddress2', 'bcity','bstate','bcountry','bphone',); | |
// add bfirstname blastname or bzipcode | |
// Loop through the $remove_fields array and unset each billing field to make it optional. | |
foreach($remove_fields as $field){ | |
unset($pmpro_required_billing_fields[$field]); | |
} | |
return $pmpro_required_billing_fields; | |
} | |
add_filter('pmpro_required_billing_fields', 'my_pmpro_remove_billing_required', 50 ); | |
add_action( 'wp_head', 'wp_head_hide_billing_fields' ); | |
function wp_head_hide_billing_fields() { | |
global $pmpro_pages; | |
if ( empty( $pmpro_pages ) || ( ! is_page( $pmpro_pages['checkout'] ) && ! is_page( $pmpro_pages['billing'] ) ) ) { | |
return; | |
} | |
?> | |
<style> | |
/* .pmpro_form_field.pmpro_form_field-text.pmpro_form_field-bfirstname, */ | |
/*.pmpro_form_field.pmpro_form_field-text.pmpro_form_field-blastname,*/ | |
.pmpro_form_field.pmpro_form_field-text.pmpro_form_field-baddress1, | |
.pmpro_form_field.pmpro_form_field-text.pmpro_form_field-baddress2, | |
.pmpro_form_field.pmpro_form_field-text.pmpro_form_field-bcity, | |
.pmpro_form_field.pmpro_form_field-text.pmpro_form_field-bstate, | |
/* .pmpro_form_field.pmpro_form_field-text.pmpro_form_field-bzipcode, */ | |
.pmpro_form_field.pmpro_form_field-select.pmpro_form_field-bcountry, | |
.pmpro_form_field.pmpro_form_field-text.pmpro_form_field-bphone | |
{ | |
display: none; | |
} | |
</style> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment