Option for free shipping if should ignore discounts or not

This commit is contained in:
boghy933 2019-10-06 01:16:22 +02:00
parent 0d50dbc3c7
commit 3bf721b023
1 changed files with 18 additions and 5 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 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();
}
}