Skip to content

Commit

Permalink
fix: 選擇最小運費,運送方法消失
Browse files Browse the repository at this point in the history
  • Loading branch information
j7-dev committed Jan 2, 2025
1 parent ce823e7 commit 21d5fa8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 66 deletions.
64 changes: 0 additions & 64 deletions admin/class-woomp-shipping-flat-rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,70 +184,6 @@ public function init() {
add_action( 'admin_footer', [ $this, 'enqueue_admin_js' ], 10 );
}

/**
* 檢查運送方式是否可用
*
* @param array $package 運送包裹資訊.
* @return bool
*/
public function is_available( $package ) {
$has_coupon = false;
$has_met_min_amount = false;

$requires = $this->requires ?? $this->cost_requires ?? '';

if ( in_array( $requires, [ 'coupon', 'either', 'both' ], true ) ) {
$coupons = WC()->cart->get_coupons();

if ( $coupons ) {
foreach ( $coupons as $code => $coupon ) {
if ( $coupon->is_valid() && $coupon->get_free_shipping() ) {
$has_coupon = true;
break;
}
}
}
}

if ( in_array( $requires, [ 'min_amount', 'either', 'both' ], true ) ) {
$total = WC()->cart->get_displayed_subtotal();

if ( WC()->cart->display_prices_including_tax() ) {
$total = $total - WC()->cart->get_discount_tax();
}

if ( 'no' === $this->ignore_discounts ) {
$total = $total - WC()->cart->get_discount_total();
}

$total = NumberUtil::round( $total, wc_get_price_decimals() );

if ( $total >= $this->min_amount ) {
$has_met_min_amount = true;
}
}

switch ( $requires ) {
case 'min_amount':
$is_available = $has_met_min_amount;
break;
case 'coupon':
$is_available = $has_coupon;
break;
case 'both':
$is_available = $has_met_min_amount && $has_coupon;
break;
case 'either':
$is_available = $has_met_min_amount || $has_coupon;
break;
default:
$is_available = true;
break;
}

return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', $is_available, $package, $this );
}

/**
* 計算運費金額
*
Expand Down
2 changes: 1 addition & 1 deletion public/class-woomp-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public static function get_diff_amount( $method, $check_requires_list, $original
*/
public static function get_diff_amount_by_settings( $settings, $check_requires_list, $original = false ): float|null {

$requires = $settings['cost_requires'] ?? ( $settings['requires'] ?? '' );
$requires = @$settings['cost_requires'] ?: @$settings['requires'];
$ignore_discounts = $settings['ignore_discounts'] ?? 'no';
$min_amount = $settings['min_amount'] ?? 0;

Expand Down
2 changes: 1 addition & 1 deletion woomp.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: 好用版擴充 MorePower Addon for WooCommerce
* Plugin URI: https://morepower.club/morepower-addon/
* Description: WooCommerce 好用版擴充,改善結帳流程與可變商品等區塊,並整合多項金流,讓 WooCommerce 更符合亞洲人使用習慣。
* Version: 3.4.53
* Version: 3.4.54
* Author: MorePower
* Author URI: https://morepower.club
* License: GPL-2.0+
Expand Down

0 comments on commit 21d5fa8

Please sign in to comment.