Last active
February 3, 2017 08:37
-
-
Save rynaldos-zz/75c93a05fcb12ef179a8 to your computer and use it in GitHub Desktop.
[WooCommerce] Make the VAT field required for select countries
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
add_action('woocommerce_checkout_process', 'wc_force_vat_field_to_be_not_empty'); | |
function wc_force_vat_field_to_be_not_empty() { | |
global $woocommerce; | |
// Define countries where VAT field is mandatory | |
$eu_countries = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SI', 'SK'); | |
// Check if customer is in one of those countries | |
if( in_array( $woocommerce->customer->get_country(), $eu_countries ) ) { | |
// Check if VAT field isn't empty | |
if ( ! $_POST['vat_number'] ) | |
// Create notice | |
wc_add_notice( __( 'Please enter your VAT number.' ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment