Forked from ipokkel/hide-stripe-billing-address-fields.php
Last active
September 19, 2024 13:44
-
-
Save kimwhite/5a4f2d79f68e14b41efbe8f35c8fd23b to your computer and use it in GitHub Desktop.
Force remove BrainTree billing fields on checkout and billing
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 | |
function hide_address_on_billing_update_if_braintree() { | |
global $pmpro_pages, $gateway; | |
// Bail if necessary | |
if ( empty( $pmpro_pages ) || ( ! is_page( $pmpro_pages['checkout'] ) && ! is_page( $pmpro_pages['billing'] ) ) ) { | |
return; | |
} | |
// Filter out BrainTree billing fields | |
if ( ! empty( $gateway ) && 'braintree' === $gateway ) { | |
add_filter( 'pmpro_include_billing_address_fields', '__return_false' ); | |
} | |
} | |
add_action( 'wp_head', 'hide_address_on_billing_update_if_braintree' ); | |
function my_pmpro_not_required_billing_fields( $fields ) { | |
if ( is_array( $fields ) ) { | |
unset( $fields['bfirstname'] ); | |
unset( $fields['blastname'] ); | |
unset( $fields['baddress1'] ); | |
unset( $fields['baddress2'] ); | |
unset( $fields['bcity'] ); | |
unset( $fields['bstate'] ); | |
unset( $fields['bzipcode'] ); | |
unset( $fields['bcountry'] ); | |
unset( $fields['bphone'] ); | |
} | |
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_not_required_billing_fields', 50, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment