Per order shipping with classes
This commit is contained in:
parent
17ccf1f92d
commit
16853cb6f6
|
@ -274,6 +274,4 @@ function woocommerce_shipping_class_description() {
|
|||
|
||||
echo wpautop(__('Shipping classes can be used to group products of similar type. These groups can then be used by certain shipping methods to provide different rates to different products.', 'woothemes'));
|
||||
|
||||
echo wpautop(__('You can drag and drop to re-order your shipping classes - if an order contains items with multiple classes, the top most class will be used if the shipping cost is per-order.', 'woothemes'));
|
||||
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ jQuery(document).ready(function($) {
|
|||
$('div.woocommerce_tabs ul.tabs li a').click(function(){
|
||||
|
||||
var $tab = $(this);
|
||||
var $tabs_wrapper = tab.closest('div.woocommerce_tabs');
|
||||
var $tabs_wrapper = $tab.closest('div.woocommerce_tabs');
|
||||
|
||||
$('ul.tabs li', $tabs_wrapper).removeClass('active');
|
||||
$('div.panel', $tabs_wrapper).hide();
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -43,6 +43,7 @@ class woocommerce_product {
|
|||
var $min_variation_price;
|
||||
var $max_variation_price;
|
||||
var $featured;
|
||||
var $shipping_class;
|
||||
|
||||
/**
|
||||
* Loads all product data from custom fields
|
||||
|
@ -687,6 +688,15 @@ class woocommerce_product {
|
|||
return get_the_term_list($this->id, 'product_tag', $before, $sep, $after);
|
||||
}
|
||||
|
||||
/** Returns the product shipping class */
|
||||
function get_shipping_class() {
|
||||
if (!$this->shipping_class) :
|
||||
$classes = get_the_terms( $this->id, 'product_shipping_class' );
|
||||
$this->shipping_class = (isset($classes[0])) ? $classes[0]->slug : '';
|
||||
endif;
|
||||
return $this->shipping_class;
|
||||
}
|
||||
|
||||
/** Get and return related products */
|
||||
function get_related( $limit = 5 ) {
|
||||
global $woocommerce;
|
||||
|
|
|
@ -122,19 +122,59 @@ class flat_rate extends woocommerce_shipping_method {
|
|||
$this->shipping_tax = 0;
|
||||
|
||||
if ($this->type=='order') :
|
||||
|
||||
$cost = null;
|
||||
$fee = null;
|
||||
|
||||
if (sizeof($this->flat_rates)>0) :
|
||||
|
||||
$found_shipping_classes = array();
|
||||
|
||||
// Find shipping class
|
||||
if (sizeof($woocommerce->cart->get_cart())>0) : foreach ($woocommerce->cart->get_cart() as $item_id => $values) : $found_shipping_classes[] = $values['data']->get_shipping_class(); endforeach; endif;
|
||||
|
||||
$found_shipping_classes = array_unique($found_shipping_classes);
|
||||
|
||||
// Find most expensive class (if found)
|
||||
foreach ($found_shipping_classes as $shipping_class) :
|
||||
if (isset($this->flat_rates[$shipping_class])) :
|
||||
if ($this->flat_rates[$shipping_class]['cost'] > $cost) :
|
||||
$cost = $this->flat_rates[$shipping_class]['cost'];
|
||||
$fee = $this->flat_rates[$shipping_class]['fee'];
|
||||
endif;
|
||||
else :
|
||||
// No matching classes so use defaults
|
||||
if ($this->cost > $cost) :
|
||||
$cost = $this->cost;
|
||||
$fee = $this->fee;
|
||||
endif;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
endif;
|
||||
|
||||
// Default rates
|
||||
if (is_null($cost)) :
|
||||
$cost = $this->cost;
|
||||
$fee = $this->fee;
|
||||
endif;
|
||||
|
||||
// Shipping for whole order
|
||||
$this->shipping_total = $this->cost + $this->get_fee( $this->fee, $woocommerce->cart->cart_contents_total );
|
||||
$this->shipping_total = $cost + $this->get_fee( $fee, $woocommerce->cart->cart_contents_total );
|
||||
|
||||
if ( get_option('woocommerce_calc_taxes')=='yes' && $this->tax_status=='taxable' ) :
|
||||
|
||||
$rate = $_tax->get_shipping_tax_rate();
|
||||
if ($rate>0) :
|
||||
$tax_amount = $_tax->calc_shipping_tax( $this->shipping_total, $rate );
|
||||
|
||||
$this->shipping_tax = $this->shipping_tax + $tax_amount;
|
||||
endif;
|
||||
endif;
|
||||
else :
|
||||
|
||||
elseif ($this->type=='class') :
|
||||
// Shipping per class
|
||||
$cost = 0;
|
||||
|
||||
elseif ($this->type=='item') :
|
||||
// Shipping per item
|
||||
if (sizeof($woocommerce->cart->get_cart())>0) : foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
|
||||
$_product = $values['data'];
|
||||
|
|
Loading…
Reference in New Issue