Forked from femiyb/unset-and-hide-billing-state-field.php
Last active
July 7, 2021 13:01
-
-
Save MaryOJob/a9f31336863b13905be87bea52635f3d to your computer and use it in GitHub Desktop.
PMPro - Remove required * from some billing fields and then hide these fields with CSS
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 // Do NOT copy this line | |
/* | |
* Remove required * from some billing fields and then hide these fields with CSS | |
* Add this to your PMPro Customization Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
add_action( 'pmpro_required_billing_fields', 'my_pmpro_required_billing_fields' ); | |
function my_pmpro_required_billing_fields( $fields ) { | |
if ( is_array( $fields ) ) { | |
unset( $fields['blastname'] ); | |
unset( $fields['baddress1'] ); | |
unset( $fields['baddress2'] ); | |
unset( $fields['bcity'] ); | |
unset( $fields['bstate'] ); | |
unset( $fields['bzipcode'] ); | |
unset( $fields['bcountry'] ); | |
} | |
return $fields; | |
} | |
// Hide state form field by adding CSS to the page head. | |
function my_pmpro_hide_billing_fields_css() { | |
global $pmpro_pages; | |
if ( empty( $pmpro_pages ) || ( ! is_page( $pmpro_pages['checkout'] ) && ! is_page( $pmpro_pages['billing'] ) ) ) { | |
return; | |
} | |
?> | |
<style> | |
div.pmpro_checkout-field-blastname, | |
div.pmpro_checkout-field-baddress1, | |
div.pmpro_checkout-field-baddress2, | |
div.pmpro_checkout-field-bcity, | |
div.pmpro_checkout-field-bstate, | |
div.pmpro_checkout-field-bzipcode, | |
div.pmpro_checkout-field-bcountry { | |
display: none; | |
} | |
</style> | |
<?php | |
} | |
add_action( 'wp_head', 'my_pmpro_hide_billing_fields_css' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment