From b682c0550e54b2de7e161c426e693e4e531bdcb4 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 16 Jun 2016 12:23:02 +0100 Subject: [PATCH] Allow max_fee in addition to min_fee in flat rate costs fields. Closes #11151 --- .../shipping/flat-rate/class-wc-shipping-flat-rate.php | 7 ++++++- .../shipping/flat-rate/includes/settings-flat-rate.php | 4 ++-- readme.txt | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php index f91115eac44..4973956a41d 100644 --- a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php +++ b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php @@ -98,7 +98,8 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { public function fee( $atts ) { $atts = shortcode_atts( array( 'percent' => '', - 'min_fee' => '' + 'min_fee' => '', + 'max_fee' => '', ), $atts ); $calculated_fee = 0; @@ -111,6 +112,10 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method { $calculated_fee = $atts['min_fee']; } + if ( $atts['max_fee'] && $calculated_fee > $atts['max_fee'] ) { + $calculated_fee = $atts['max_fee']; + } + return $calculated_fee; } diff --git a/includes/shipping/flat-rate/includes/settings-flat-rate.php b/includes/shipping/flat-rate/includes/settings-flat-rate.php index cbf7d0e1866..e6f304cf4c3 100644 --- a/includes/shipping/flat-rate/includes/settings-flat-rate.php +++ b/includes/shipping/flat-rate/includes/settings-flat-rate.php @@ -4,7 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -$cost_desc = __( 'Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].', 'woocommerce' ) . '
' . __( 'Supports the following placeholders: [qty] = number of items, [cost] = cost of items, [fee percent="10" min_fee="20"] = Percentage based fee.', 'woocommerce' ); +$cost_desc = __( 'Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].', 'woocommerce' ) . '

' . __( 'Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent="10" min_fee="20" max_fee=""] for percentage based fees.', 'woocommerce' ); /** * Settings for flat rate shipping. @@ -32,7 +32,7 @@ $settings = array( 'type' => 'text', 'placeholder' => '', 'description' => $cost_desc, - 'default' => '', + 'default' => '0', 'desc_tip' => true ) ); diff --git a/readme.txt b/readme.txt index c0fb9ff84d1..61c9d5f8ab0 100644 --- a/readme.txt +++ b/readme.txt @@ -174,6 +174,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Tweak - Hide 'payment methods' screen if no methods support it. * Tweak - If shipping method count changes, reset to default. * Tweak - Avoid normalization of zone postcodes so wildcard matching can be performed on postcodes with spaces. E.g. SP1 * +* Tweak - Allow max_fee in addition to min_fee in flat rate costs fields. = 2.6.0 - 14/06/16 = * Feature - Introduced Shipping Zone functionality, and re-usable instance based shipping methods.