Plugin Directory

Changeset 3235159


Ignore:
Timestamp:
02/05/2025 06:07:27 AM (14 months ago)
Author:
webimpian
Message:

Bug: Fixed checkout fee calculation to properly handle coupon discounts

Location:
bayarcash-wc
Files:
383 added
3 edited

Legend:

Unmodified
Added
Removed
  • bayarcash-wc/trunk/bayarcash-wc.php

    r3219889 r3235159  
    1313 * Plugin Name:         Bayarcash WC
    1414 * Plugin URI:          https://bayarcash.com/
    15  * Version:             4.3.2
     15 * Version:             4.3.3
    1616 * Description:         Accept payment from Malaysia. Bayarcash support FPX, Direct Debit, DuitNow OBW & DuitNow QR payment channels.
    1717 * Author:              Web Impian
  • bayarcash-wc/trunk/includes/src/BayarcashCheckoutFee.php

    r3219889 r3235159  
    5050            return;
    5151        }
     52
    5253        $chosen_payment_method = WC()->session->get('chosen_payment_method');
    5354        if (!$this->is_bayarcash_payment_method($chosen_payment_method)) {
    5455            return;
    5556        }
     57
    5658        $settings = get_option('woocommerce_' . $chosen_payment_method . '_settings', []);
     59
    5760        // Extract fee-related settings
    5861        $fee_settings = [
     
    6366            'additional_charge_name' => $settings['additional_charge_name'] ?? '',
    6467        ];
     68
    6569        if ($fee_settings['enable_additional_charges'] !== 'yes') {
    6670            return;
    6771        }
     72
    6873        if (empty($fee_settings['additional_charge_type']) || empty($fee_settings['additional_charge_amount'])) {
    6974            return;
    7075        }
     76
    7177        $charge_type = $fee_settings['additional_charge_type'];
    7278        $charge_amount = floatval($fee_settings['additional_charge_amount']);
     
    7783        }
    7884
    79         $cart_total = $cart->get_subtotal() + $cart->get_shipping_total();
     85        // Calculate total after discounts
     86        $cart_total = $cart->get_subtotal();
     87        $discount_total = $cart->get_discount_total();
     88        $shipping_total = $cart->get_shipping_total();
     89
     90        // Calculate the actual total after discounts
     91        $total_after_discounts = $cart_total - $discount_total + $shipping_total;
     92
     93        // Skip fee if total after discounts is 0 or negative
     94        if ($total_after_discounts <= 0) {
     95            return;
     96        }
     97
    8098        $fee = 0;
    8199        $fee_name = !empty($fee_settings['additional_charge_name'])
     
    89107                break;
    90108            case 'percentage':
    91                 $fee = ($cart_total * $charge_amount) / 100;
     109                // Calculate percentage based on total after discounts
     110                $fee = ($total_after_discounts * $charge_amount) / 100;
    92111                $fee_label = sprintf('%s (%s%%)', $fee_name, $charge_amount);
    93112                break;
    94113            case 'both':
    95114                $fixed_fee = $charge_amount;
    96                 $percentage_fee = ($cart_total * $charge_percentage) / 100;
     115                // Calculate percentage based on total after discounts
     116                $percentage_fee = ($total_after_discounts * $charge_percentage) / 100;
    97117                $fee = $fixed_fee + $percentage_fee;
    98118                $fee_label = sprintf('%s (RM %s + %s%%)', $fee_name, number_format($charge_amount, 2), $charge_percentage);
  • bayarcash-wc/trunk/readme.txt

    r3219889 r3235159  
    55Tested up to: 6.7
    66Requires PHP: 7.4
    7 Stable tag: 4.3.2
     7Stable tag: 4.3.3
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.txt
     
    8989== Changelog ==
    9090
     91= 4.3.3 =
     92* Bug: Fixed checkout fee calculation to properly handle coupon discounts
     93
    9194= 4.3.2 =
    9295* Added support for multiple merchant accounts of Bayarcash for FPX payment channels
Note: See TracChangeset for help on using the changeset viewer.