Last active
November 27, 2024 09:14
-
-
Save ipokkel/246cd14bdf16f76516f43acbabada048 to your computer and use it in GitHub Desktop.
Remove some billing address fields from checkout.
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 | |
/** | |
* This recipe removes some billing fields from the checkout page. | |
* | |
* Note: Make sure your Gateway doesn't require these fields. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_not_required_billing_fields( $fields ) { | |
if ( is_array( $fields ) ) { | |
unset( $fields['baddress1'] ); | |
unset( $fields['baddress2'] ); | |
unset( $fields['bcity'] ); | |
unset( $fields['bstate'] ); | |
unset( $fields['bzipcode'] ); | |
unset( $fields['bcountry'] ); | |
} | |
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 ); | |
// 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-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