Method availability (country) for local pickup/delivery

This commit is contained in:
Mike Jolley 2012-02-17 20:39:50 +00:00
parent 2db4f40751
commit a300dae69c
3 changed files with 81 additions and 0 deletions

View File

@ -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 {
</table> <?php
}
function is_available() {
global $woocommerce;
if ($this->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; }

View File

@ -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 {
</table> <?php
}
function is_available() {
global $woocommerce;
if ($this->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; }

View File

@ -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