Skip to content

Commit

Permalink
woocommerce_calc_discounts_sequentially option to keep backwards comp…
Browse files Browse the repository at this point in the history
…atible
  • Loading branch information
mikejolley committed Mar 24, 2015
1 parent 5e538b8 commit aed8ae3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
25 changes: 18 additions & 7 deletions includes/admin/settings/class-wc-settings-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,24 @@ public function get_settings() {
array( 'title' => __( 'Checkout Process', 'woocommerce' ), 'type' => 'title', 'id' => 'checkout_process_options' ),

array(
'title' => __( 'Coupons', 'woocommerce' ),
'desc' => __( 'Enable the use of coupons', 'woocommerce' ),
'id' => 'woocommerce_enable_coupons',
'default' => 'yes',
'type' => 'checkbox',
'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
'autoload' => false
'title' => __( 'Coupons', 'woocommerce' ),
'desc' => __( 'Enable the use of coupons', 'woocommerce' ),
'id' => 'woocommerce_enable_coupons',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
'autoload' => false
),

array(
'desc' => __( 'Calculate coupon discounts sequentially', 'woocommerce' ),
'id' => 'woocommerce_calc_discounts_sequentially',
'default' => 'no',
'type' => 'checkbox',
'desc_tip' => __( 'When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.', 'woocommerce' ),
'checkboxgroup' => 'end',
'autoload' => false
),

array(
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ public function get_discounted_price( $values, $price, $add_totals = false ) {

foreach ( $this->coupons as $code => $coupon ) {
if ( $coupon->is_valid() && ( $coupon->is_valid_for_product( $product, $values ) || $coupon->is_valid_for_cart() ) ) {
$discount_amount = $coupon->get_discount_amount( $undiscounted_price, $values, $single = true );
$discount_amount = $coupon->get_discount_amount( ( 'yes' === get_option( 'woocommerce_calc_discounts_sequentially', 'no' ) ? $price : $undiscounted_price ), $values, $single = true );
$discount_amount = min( $price, $discount_amount );
$price = max( $price - $discount_amount, 0 );

Expand Down
16 changes: 16 additions & 0 deletions includes/updates/woocommerce-update-2.4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Update WC to 2.4.0
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Updates
* @version 2.4.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Maintain the old coupon logic for upgrades
update_option( 'woocommerce_calc_discounts_sequentially', 'yes' )

0 comments on commit aed8ae3

Please sign in to comment.