Last active
September 4, 2015 13:12
-
-
Save chrdesigner/786a33b61ac7a391b3bd to your computer and use it in GitHub Desktop.
Function - Disable Checkout for some Countries and States
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 | |
/* | |
* Function - Disable Checkout for some Countries and States | |
*/ | |
function wc_checkout_validation() { | |
$shipping_country = ! empty( $_POST['shipping_country'] ) ? $_POST['shipping_country'] : $_POST['billing_country']; | |
$shipping_state = ! empty( $_POST['shipping_state'] ) ? $_POST['shipping_state'] : $_POST['billing_state']; | |
// Add here States : More example look here -> wp-content/plugins/woocommerce/i18n/states/ | |
$excluded_states = array( | |
'SP', | |
'DF', | |
'RS', | |
); | |
// Verification if you are in Brazil : More example look here -> wp-content/plugins/woocommerce/i18n/countries.php | |
if ( 'BR' != $shipping_country ) { | |
wc_add_notice( __( 'Desculpem-nos, infelizmente não vendemos para fora do Brasil.', 'odin' ), 'error' ); | |
} | |
// Verification Brazilian States | |
if ( in_array( $shipping_state, $excluded_states ) ) { | |
// Here you generate State Label for your Alert, if you use a different country. Please, specific below your correct country. | |
$states = WC()->countries->get_states( 'BR' ); | |
$state = $states[$shipping_state]; | |
wc_add_notice( sprintf( __( 'Desculpem-nos, infelizmente não realizamos entregas para <strong>%s</strong>.', 'odin' ), $state ), 'error' ); | |
} | |
} | |
add_action( 'woocommerce_checkout_process', 'wc_checkout_validation' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment