Feature - Local delivery cost per item condition

This commit is contained in:
Mike Jolley 2012-04-16 10:13:13 +01:00
parent f6ba5187fa
commit 27b2c87600
4 changed files with 26 additions and 11 deletions

View File

@ -1287,13 +1287,13 @@ function woocommerce_settings() {
$current = ( empty( $_GET['section'] ) ) ? 'class="current"' : '';
$links = array( '<a href="' . remove_query_arg( 'saved', remove_query_arg( 'section' ) ) . '" ' . $current . '>' . __('Shipping Options', 'woocommerce') . '</a>' );
$links = array( '<a href="' . admin_url('admin.php?page=woocommerce&tab=shipping') . '" ' . $current . '>' . __('Shipping Options', 'woocommerce') . '</a>' );
foreach ( $woocommerce->shipping->shipping_methods as $method ) {
$title = ( isset( $method->method_title ) && $method->method_title) ? ucwords($method->method_title) : ucwords($method->id);
$current = ( ! empty( $_GET['section'] ) && $method->id == urldecode( $_GET['section'] ) ) ? 'class="current"' : '';
$links[] = '<a href="' . remove_query_arg( 'saved', add_query_arg( 'section', $method->id ) ) . '"' . $current . '>' . $title . '</a>';
$links[] = '<a href="' . add_query_arg( 'section', $method->id, admin_url('admin.php?page=woocommerce&tab=shipping') ) . '"' . $current . '>' . $title . '</a>';
}
echo '<ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';

View File

@ -28,6 +28,7 @@ class WC_Local_Delivery extends WC_Shipping_Method {
// Define user set variables
$this->enabled = empty( $this->settings['enabled'] ) ? 'no' : $this->settings['enabled'];
$this->title = empty( $this->settings['title'] ) ? '' : $this->settings['title'];
$this->type = $this->settings['type'];
$this->fee = empty( $this->settings['fee'] ) ? '' : $this->settings['fee'];
$this->type = empty( $this->settings['type'] ) ? '' : $this->settings['type'];
$this->codes = empty( $this->settings['codes'] ) ? '' : $this->settings['codes'];
@ -40,10 +41,22 @@ class WC_Local_Delivery extends WC_Shipping_Method {
function calculate_shipping( $package = array() ) {
global $woocommerce;
$shipping_total = 0;
$fee = ( trim( $this->fee ) == '' ) ? 0 : $this->fee;
if ( $this->type =='fixed' ) $shipping_total = $this->fee;
if ( $this->type =='percent' ) $shipping_total = $package['contents_cost'] * ( $this->fee / 100 );
if ( $this->type == 'product' ) {
foreach ( $woocommerce->cart->get_cart() as $item_id => $values ) {
$_product = $values['data'];
if ( $values['quantity'] > 0 && $_product->needs_shipping() )
$shipping_total += $this->fee * $values['quantity'];
}
}
$rate = array(
'id' => $this->id,
'label' => $this->title,
@ -74,8 +87,9 @@ class WC_Local_Delivery extends WC_Shipping_Method {
'description' => __( 'How to calculate delivery charges', 'woocommerce' ),
'default' => 'fixed',
'options' => array(
'fixed' => __('Fixed Amount', 'woocommerce'),
'percent' => __('Percentage of Cart Total', 'woocommerce'),
'fixed' => __('Fixed amount', 'woocommerce'),
'percent' => __('Percentage of cart total', 'woocommerce'),
'product' => __('Fixed amount per product', 'woocommerce'),
),
),
'fee' => array(

View File

@ -118,27 +118,27 @@ class WC_Shipping_Method extends WC_Settings_API {
$this->rates[] = new WC_Shipping_Rate( $id, $label, $total_cost, $taxes );
}
function is_available() {
function is_available( $package ) {
global $woocommerce;
if ($this->enabled=="no")
return false;
if (isset($woocommerce->cart->cart_contents_total) && isset($this->min_amount) && $this->min_amount && $this->min_amount > $woocommerce->cart->cart_contents_total)
if ( isset( $woocommerce->cart->cart_contents_total ) && isset( $this->min_amount ) && $this->min_amount && $this->min_amount > $woocommerce->cart->cart_contents_total )
return false;
$ship_to_countries = '';
if ($this->availability == 'specific') :
if ( $this->availability == 'specific' ) :
$ship_to_countries = $this->countries;
else :
if (get_option('woocommerce_allowed_countries')=='specific') :
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;
if ( is_array( $ship_to_countries ) ) :
if ( ! in_array( $package['destination']['country'], $ship_to_countries ) ) return false;
endif;
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true );

View File

@ -153,6 +153,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Shortcode to show a list of all product categories
* Feature - Minimum fee option for flat rate shipping
* Feature - "Package" support for shipping calculations - allows third parties to split the cart up to calc shipping. Also caches packages meaning the cart shipping only needs to be calculated once (until totals or customer location changes)
* Feature - Local delivery cost per item condition
* Tweak - Redesigned variation panels and variation bulk edit to make them easier to use and expand.
* Tweak - Show multiple success messages/error messages if added, rather than one or the other
* Tweak - Adding an item to an order now uses the ajax style product finder