Last active
October 10, 2023 20:40
-
-
Save clifgriffin/818a5ac1e8809e0ad8a4cf079e2590d4 to your computer and use it in GitHub Desktop.
Remove billing address fields for digital orders in Checkout for WooCommerce
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 include the opening php tag. | |
// Place in your theme's functions.php file | |
add_filter( 'cfw_get_billing_checkout_fields', 'remove_checkout_fields', 100 ); | |
function remove_checkout_fields( $fields ) { | |
unset( $fields['billing_company'] ); | |
unset( $fields['billing_city'] ); | |
unset( $fields['billing_postcode'] ); | |
unset( $fields['billing_country'] ); | |
unset( $fields['billing_state'] ); | |
unset( $fields['billing_address_1'] ); | |
unset( $fields['billing_address_2'] ); | |
return $fields; | |
} | |
// Set billing address fields to not required | |
add_filter( 'woocommerce_checkout_fields', 'unrequire_checkout_fields' ); | |
function unrequire_checkout_fields( $fields ) { | |
$fields['billing']['billing_company']['required'] = false; | |
$fields['billing']['billing_city']['required'] = false; | |
$fields['billing']['billing_postcode']['required'] = false; | |
$fields['billing']['billing_country']['required'] = false; | |
$fields['billing']['billing_state']['required'] = false; | |
$fields['billing']['billing_address_1']['required'] = false; | |
$fields['billing']['billing_address_2']['required'] = false; | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice stuff. Thank you!