Last active
December 23, 2015 20:59
-
-
Save etiennetremel/6693162 to your computer and use it in GitHub Desktop.
WooCommerce Allow Shipping Countries: Make orders to be shipped only in specific country, display message if the customer don't choose an allowed one.
This file contains hidden or 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 | |
/** | |
* WOOCOMMERCE ALLOW SHIPPING COUNTRIES | |
* Make orders to be shipped only in specific country, display message if the customer don't choose an allowed one. | |
*/ | |
function custom_checkout_process() { | |
global $woocommerce; | |
// Block orders to be shipped to other country than New Zealand, United States and Australia | |
$allowed_shipping_countries = array( 'AU', 'NZ', 'US' ); | |
$error_message = 'We only deliver to Australia, New Zealand and United States'; | |
if ( isset( $_POST['shiptobilling'] ) && $_POST['shiptobilling'] == '1' ) { | |
if ( ! in_array( $_POST['billing_country'], $allowed_shipping_countries ) ) | |
$woocommerce->add_error( $error_message ); | |
} else { | |
if ( ! in_array( $_POST['shipping_country'], $allowed_shipping_countries ) ) | |
$woocommerce->add_error( $error_message ); | |
} | |
} | |
add_action('woocommerce_checkout_process', 'custom_checkout_process'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment