Merge pull request #24776 from boghy933/feature/24754

Option for free shipping if should ignore discounts or not
This commit is contained in:
Rodrigo Primo 2020-03-06 13:10:45 -03:00 committed by GitHub
commit 1910420896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 6 deletions

View File

@ -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 coupons discounts', 'woocommerce' ),
'type' => 'checkbox',
'description' => __( 'Discounts will not be applied to the minimum order amount.', 'woocommerce' ),
'default' => 'no',
'desc_tip' => true,
),
);
}
@ -143,11 +151,15 @@ 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_total(), wc_get_price_decimals() );
$total = $total - WC()->cart->get_discount_tax();
}
if ( 'no' === $this->ignore_discounts ) {
$total = $total - WC()->cart->get_discount_total();
}
$total = round( $total, wc_get_price_decimals() );
if ( $total >= $this->min_amount ) {
$has_met_min_amount = true;
}
@ -203,10 +215,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();
}
}