Feature - Local delivery cost per item condition
This commit is contained in:
parent
f6ba5187fa
commit
27b2c87600
|
@ -1287,13 +1287,13 @@ function woocommerce_settings() {
|
||||||
|
|
||||||
$current = ( empty( $_GET['section'] ) ) ? 'class="current"' : '';
|
$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 ) {
|
foreach ( $woocommerce->shipping->shipping_methods as $method ) {
|
||||||
$title = ( isset( $method->method_title ) && $method->method_title) ? ucwords($method->method_title) : ucwords($method->id);
|
$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"' : '';
|
$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" />';
|
echo '<ul class="subsubsub"><li>' . implode(' | </li><li>', $links) . '</li></ul><br class="clear" />';
|
||||||
|
|
|
@ -28,6 +28,7 @@ class WC_Local_Delivery extends WC_Shipping_Method {
|
||||||
// Define user set variables
|
// Define user set variables
|
||||||
$this->enabled = empty( $this->settings['enabled'] ) ? 'no' : $this->settings['enabled'];
|
$this->enabled = empty( $this->settings['enabled'] ) ? 'no' : $this->settings['enabled'];
|
||||||
$this->title = empty( $this->settings['title'] ) ? '' : $this->settings['title'];
|
$this->title = empty( $this->settings['title'] ) ? '' : $this->settings['title'];
|
||||||
|
$this->type = $this->settings['type'];
|
||||||
$this->fee = empty( $this->settings['fee'] ) ? '' : $this->settings['fee'];
|
$this->fee = empty( $this->settings['fee'] ) ? '' : $this->settings['fee'];
|
||||||
$this->type = empty( $this->settings['type'] ) ? '' : $this->settings['type'];
|
$this->type = empty( $this->settings['type'] ) ? '' : $this->settings['type'];
|
||||||
$this->codes = empty( $this->settings['codes'] ) ? '' : $this->settings['codes'];
|
$this->codes = empty( $this->settings['codes'] ) ? '' : $this->settings['codes'];
|
||||||
|
@ -39,11 +40,23 @@ class WC_Local_Delivery extends WC_Shipping_Method {
|
||||||
|
|
||||||
function calculate_shipping( $package = array() ) {
|
function calculate_shipping( $package = array() ) {
|
||||||
global $woocommerce;
|
global $woocommerce;
|
||||||
|
|
||||||
|
$shipping_total = 0;
|
||||||
$fee = ( trim( $this->fee ) == '' ) ? 0 : $this->fee;
|
$fee = ( trim( $this->fee ) == '' ) ? 0 : $this->fee;
|
||||||
|
|
||||||
if ( $this->type =='fixed' ) $shipping_total = $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 =='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(
|
$rate = array(
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'label' => $this->title,
|
'label' => $this->title,
|
||||||
|
@ -74,8 +87,9 @@ class WC_Local_Delivery extends WC_Shipping_Method {
|
||||||
'description' => __( 'How to calculate delivery charges', 'woocommerce' ),
|
'description' => __( 'How to calculate delivery charges', 'woocommerce' ),
|
||||||
'default' => 'fixed',
|
'default' => 'fixed',
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'fixed' => __('Fixed Amount', 'woocommerce'),
|
'fixed' => __('Fixed amount', 'woocommerce'),
|
||||||
'percent' => __('Percentage of Cart Total', 'woocommerce'),
|
'percent' => __('Percentage of cart total', 'woocommerce'),
|
||||||
|
'product' => __('Fixed amount per product', 'woocommerce'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'fee' => array(
|
'fee' => array(
|
||||||
|
|
|
@ -118,27 +118,27 @@ class WC_Shipping_Method extends WC_Settings_API {
|
||||||
$this->rates[] = new WC_Shipping_Rate( $id, $label, $total_cost, $taxes );
|
$this->rates[] = new WC_Shipping_Rate( $id, $label, $total_cost, $taxes );
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_available() {
|
function is_available( $package ) {
|
||||||
global $woocommerce;
|
global $woocommerce;
|
||||||
|
|
||||||
if ($this->enabled=="no")
|
if ($this->enabled=="no")
|
||||||
return false;
|
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;
|
return false;
|
||||||
|
|
||||||
$ship_to_countries = '';
|
$ship_to_countries = '';
|
||||||
|
|
||||||
if ($this->availability == 'specific') :
|
if ( $this->availability == 'specific' ) :
|
||||||
$ship_to_countries = $this->countries;
|
$ship_to_countries = $this->countries;
|
||||||
else :
|
else :
|
||||||
if (get_option('woocommerce_allowed_countries')=='specific') :
|
if ( get_option('woocommerce_allowed_countries') == 'specific' ) :
|
||||||
$ship_to_countries = get_option('woocommerce_specific_allowed_countries');
|
$ship_to_countries = get_option('woocommerce_specific_allowed_countries');
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if (is_array($ship_to_countries)) :
|
if ( is_array( $ship_to_countries ) ) :
|
||||||
if (!in_array($woocommerce->customer->get_shipping_country(), $ship_to_countries)) return false;
|
if ( ! in_array( $package['destination']['country'], $ship_to_countries ) ) return false;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true );
|
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true );
|
||||||
|
|
|
@ -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 - Shortcode to show a list of all product categories
|
||||||
* Feature - Minimum fee option for flat rate shipping
|
* 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 - "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 - 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 - 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
|
* Tweak - Adding an item to an order now uses the ajax style product finder
|
||||||
|
|
Loading…
Reference in New Issue