Flat rate addons
This commit is contained in:
parent
02fe1b5889
commit
06587191f0
|
@ -39,6 +39,10 @@ class WC_Flat_Rate extends WC_Shipping_Method {
|
|||
$this->tax_status = $this->settings['tax_status'];
|
||||
$this->cost = $this->settings['cost'];
|
||||
$this->fee = $this->settings['fee'];
|
||||
$this->options = isset($this->settings['options']) ? $this->settings['options'] : '';
|
||||
|
||||
// Get options
|
||||
$this->options = (array) explode("\n", $this->options);
|
||||
|
||||
// Load Flat rates
|
||||
$this->get_flat_rates();
|
||||
|
@ -118,6 +122,12 @@ class WC_Flat_Rate extends WC_Shipping_Method {
|
|||
'description' => __('Fee excluding tax. Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to disable.', 'woocommerce'),
|
||||
'default' => ''
|
||||
),
|
||||
'options' => array(
|
||||
'title' => __( 'Shipping Options', 'woocommerce' ),
|
||||
'type' => 'textarea',
|
||||
'description' => __('Optional extra shipping options with additional costs (one per line). Format: <code>Option Name|Cost|Cost is per-order (yes or no)</code>. Example: <code>Priority Mail|6.95|yes</code>. If per-order is set to no, it will use "Calculation Type" setting.', 'woocommerce'),
|
||||
'default' => ''
|
||||
),
|
||||
);
|
||||
|
||||
} // End init_form_fields()
|
||||
|
@ -232,6 +242,7 @@ class WC_Flat_Rate extends WC_Shipping_Method {
|
|||
|
||||
// Per item shipping so we pass an array of costs (per item) instead of a single value
|
||||
$costs = array();
|
||||
$total_quantity = 0;
|
||||
|
||||
// Shipping per item
|
||||
foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
|
||||
|
@ -252,6 +263,8 @@ class WC_Flat_Rate extends WC_Shipping_Method {
|
|||
|
||||
$costs[$item_id] = (( $cost + $fee ) * $values['quantity']);
|
||||
|
||||
$total_quantity += $values['quantity'];
|
||||
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
|
@ -263,9 +276,47 @@ class WC_Flat_Rate extends WC_Shipping_Method {
|
|||
);
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
// Register the rate
|
||||
$this->add_rate( $rate );
|
||||
|
||||
// Add any extra rates
|
||||
if (sizeof($this->options) > 0) foreach ($this->options as $option) {
|
||||
|
||||
$this_option = explode('|', $option);
|
||||
|
||||
if (sizeof($this_option)!==3) continue;
|
||||
|
||||
$extra_rate = $rate;
|
||||
|
||||
$extra_rate['id'] = $this->id . ':' . sanitize_title($this_option[0]);
|
||||
$extra_rate['label'] = $this_option[0];
|
||||
|
||||
$per_order_cost = ($this_option[2]=='yes') ? 1 : 0;
|
||||
$this_cost = $this_option[1];
|
||||
|
||||
if (is_array($extra_rate['cost'])) {
|
||||
|
||||
if ($per_order_cost) {
|
||||
$extra_rate['cost']['order'] = $this_cost;
|
||||
} else {
|
||||
// Per-product shipping
|
||||
$extra_rate['cost']['order'] = $this_cost * $total_quantity;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// If using shipping per class, multiple the cost by the classes we found
|
||||
if (!$per_order_cost && $this->type=='class') {
|
||||
$this_cost = $this_cost * $found_shipping_classes;
|
||||
}
|
||||
|
||||
$extra_rate['cost'] = $extra_rate['cost'] + $this_cost;
|
||||
}
|
||||
|
||||
$this->add_rate( $extra_rate );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,6 +86,18 @@ class WC_Shipping_Method extends WC_Settings_API {
|
|||
endforeach;
|
||||
|
||||
endforeach;
|
||||
|
||||
// Add any cost for the order - order costs are in the key 'order'
|
||||
if (isset($cost['order'])) {
|
||||
|
||||
$rates = $_tax->get_shipping_tax_rates();
|
||||
$item_taxes = $_tax->calc_shipping_tax( $cost['order'], $rates );
|
||||
|
||||
// Sum the item taxes
|
||||
foreach (array_keys($taxes + $item_taxes) as $key) :
|
||||
$taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
|
||||
endforeach;
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Downloadable Product Permissions management via orders page - grant and revoke access to files
|
||||
* See how many times a download has been downloaded
|
||||
* Option for downloadable files to expire after X days
|
||||
* Define extra flat rate addons - e.g. priority shipping for an extra $5
|
||||
* PayPal standard goes straight to PayPal via a GET request - no more pay page/forms
|
||||
* Better mixed cart handling - option to give access to downloads after payment (processing order status)
|
||||
* Added basic API for payment gateways to hook into (for IPN etc)
|
||||
|
|
Loading…
Reference in New Issue