diff --git a/includes/shipping/free-shipping/class-wc-shipping-free-shipping.php b/includes/shipping/free-shipping/class-wc-shipping-free-shipping.php index 283c66e4b95..da689a4dda9 100644 --- a/includes/shipping/free-shipping/class-wc-shipping-free-shipping.php +++ b/includes/shipping/free-shipping/class-wc-shipping-free-shipping.php @@ -62,9 +62,10 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method { $this->init_settings(); // Define user set variables. - $this->title = $this->get_option( 'title' ); - $this->min_amount = $this->get_option( 'min_amount', 0 ); - $this->requires = $this->get_option( 'requires' ); + $this->title = $this->get_option( 'title' ); + $this->min_amount = $this->get_option( 'min_amount', 0 ); + $this->requires = $this->get_option( 'requires' ); + $this->ignore_discounts = $this->get_option( 'ignore_discounts' ); // Actions. add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); @@ -104,6 +105,13 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method { 'default' => '0', 'desc_tip' => true, ), + 'ignore_discounts' => array( + 'title' => __( 'Ignore discounts', 'woocommerce' ), + 'type' => 'checkbox', + 'description' => __( 'Discounts will not be applied to the minimum order amount.', 'woocommerce' ), + 'default' => 'no', + 'desc_tip' => true, + ), ); } @@ -143,8 +151,10 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method { $total = WC()->cart->get_displayed_subtotal(); if ( WC()->cart->display_prices_including_tax() ) { - $total = round( $total - ( WC()->cart->get_discount_total() + WC()->cart->get_discount_tax() ), wc_get_price_decimals() ); - } else { + $total = round( $total - WC()->cart->get_discount_tax(), wc_get_price_decimals() ); + } + + if ( 'no' === $this->ignore_discounts ) { $total = round( $total - WC()->cart->get_discount_total(), wc_get_price_decimals() ); } @@ -203,10 +213,13 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method { function wcFreeShippingShowHideMinAmountField( el ) { var form = $( el ).closest( 'form' ); var minAmountField = $( '#woocommerce_free_shipping_min_amount', form ).closest( 'tr' ); + var ignoreDiscountField = $( '#woocommerce_free_shipping_ignore_discounts', form ).closest( 'tr' ); if ( 'coupon' === $( el ).val() || '' === $( el ).val() ) { minAmountField.hide(); + ignoreDiscountField.hide(); } else { minAmountField.show(); + ignoreDiscountField.show(); } }