diff --git a/classes/shipping/class-wc-local-delivery.php b/classes/shipping/class-wc-local-delivery.php index 4bcf3ff435e..77e6c132436 100644 --- a/classes/shipping/class-wc-local-delivery.php +++ b/classes/shipping/class-wc-local-delivery.php @@ -82,6 +82,24 @@ class WC_Local_Delivery extends WC_Shipping_Method { 'description' => __( 'What fee do you want to charge for local delivery, disregarded if you choose free.', 'woocommerce' ), 'default' => '5' ), + 'availability' => array( + 'title' => __( 'Method availability', 'woocommerce' ), + 'type' => 'select', + 'default' => 'all', + 'class' => 'availability', + 'options' => array( + 'all' => __('All allowed countries', 'woocommerce'), + 'specific' => __('Specific Countries', 'woocommerce') + ) + ), + 'countries' => array( + 'title' => __( 'Specific Countries', 'woocommerce' ), + 'type' => 'multiselect', + 'class' => 'chosen_select', + 'css' => 'width: 450px;', + 'default' => '', + 'options' => $woocommerce->countries->countries + ) ); } @@ -94,6 +112,28 @@ class WC_Local_Delivery extends WC_Shipping_Method { enabled=="no") return false; + + $ship_to_countries = ''; + + if ($this->availability == 'specific') : + $ship_to_countries = $this->countries; + else : + if (get_option('woocommerce_allowed_countries')=='specific') : + $ship_to_countries = get_option('woocommerce_specific_allowed_countries'); + endif; + endif; + + if (is_array($ship_to_countries)) : + if (!in_array($woocommerce->customer->get_shipping_country(), $ship_to_countries)) return false; + endif; + + return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true ); + } + } function add_local_delivery_method($methods) { $methods[] = 'WC_Local_Delivery'; return $methods; } diff --git a/classes/shipping/class-wc-local-pickup.php b/classes/shipping/class-wc-local-pickup.php index b8f354e17fc..faff1d6bae4 100644 --- a/classes/shipping/class-wc-local-pickup.php +++ b/classes/shipping/class-wc-local-pickup.php @@ -59,6 +59,24 @@ class WC_Local_Pickup extends WC_Shipping_Method { 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 'default' => __( 'Local Pickup', 'woocommerce' ) ), + 'availability' => array( + 'title' => __( 'Method availability', 'woocommerce' ), + 'type' => 'select', + 'default' => 'all', + 'class' => 'availability', + 'options' => array( + 'all' => __('All allowed countries', 'woocommerce'), + 'specific' => __('Specific Countries', 'woocommerce') + ) + ), + 'countries' => array( + 'title' => __( 'Specific Countries', 'woocommerce' ), + 'type' => 'multiselect', + 'class' => 'chosen_select', + 'css' => 'width: 450px;', + 'default' => '', + 'options' => $woocommerce->countries->countries + ) ); } @@ -71,6 +89,28 @@ class WC_Local_Pickup extends WC_Shipping_Method { enabled=="no") return false; + + $ship_to_countries = ''; + + if ($this->availability == 'specific') : + $ship_to_countries = $this->countries; + else : + if (get_option('woocommerce_allowed_countries')=='specific') : + $ship_to_countries = get_option('woocommerce_specific_allowed_countries'); + endif; + endif; + + if (is_array($ship_to_countries)) : + if (!in_array($woocommerce->customer->get_shipping_country(), $ship_to_countries)) return false; + endif; + + return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true ); + } + } function add_local_pickup_method($methods) { $methods[] = 'WC_Local_Pickup'; return $methods; } diff --git a/readme.txt b/readme.txt index 6c67c7494a7..92e70172c67 100644 --- a/readme.txt +++ b/readme.txt @@ -89,6 +89,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo * Load non-minified woocommerce.js file if SCRIPT_DEBUG is on * Fix for reducing/increasing stock notifications * Don't reset shipping method on cart during every update +* Method availability (country) for local pickup/delivery = 1.4.3 - 16/02/2012 = * Fix for variation shipping class detection