Plugin Directory

Changeset 3380390


Ignore:
Timestamp:
10/18/2025 05:02:40 AM (6 months ago)
Author:
mlmsoft
Message:

Version 3.11.0

Location:
mlm-soft-integration/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • mlm-soft-integration/trunk/CHANGELOG.md

    r3378773 r3380390  
    22
    33## Changelog ##
     4
     5## 2025-10-17 - version 3.11.0
     6* Before remove the coupon, check the order status. [EWalletCartModule.php]
     7* Cancel an order containing an expired coupon. [EWalletCouponModule.php]
    48
    59## 2025-10-15 - version 3.10.0
  • mlm-soft-integration/trunk/integrations/woocommerce/paymentGateways/eWallet/modules/EWalletCartModule.php

    r3333463 r3380390  
    8585               
    8686                $order = wc_get_order($orderId);
    87                 $paymentMethod = $order->get_payment_method();
    88                 $datePaid = $order->get_date_paid();
    89                
    90                 if ( ! empty($paymentMethod) && empty($datePaid) ) {
    91                     // In this case, do not remove the coupon.
    92                     return;
     87
     88                /**
     89                 * Before remove the coupon, check the order status.
     90                 * The `CHECKOUT_DRAFT` constant will be added to the `OrderStatus` class starting with Woocommerce 10.3.0.
     91                 *
     92                 * @since 3.11.0
     93                 */
     94                if ( $order->get_status() !== 'checkout-draft' ) {
     95                    $paymentMethod = $order->get_payment_method();
     96                    $datePaid = $order->get_date_paid();
     97                   
     98                    if ( ! empty($paymentMethod) && empty($datePaid) ) {
     99                        // In this case, do not remove the coupon.
     100                        return;
     101                    }
    93102                }
    94103            }
  • mlm-soft-integration/trunk/integrations/woocommerce/paymentGateways/eWallet/modules/EWalletCouponModule.php

    r3333463 r3380390  
    99use MLMSoft\traits\SingletonTrait;
    1010use WC_Coupon;
     11use Automattic\WooCommerce\Enums\OrderStatus;
    1112
    1213class EWalletCouponModule
     
    113114            $coupon = new EWalletCoupon($code);
    114115            if ($coupon->get_usage_count(null)) {
     116                /**
     117                 * Cancel an order containing an expired coupon.
     118                 *
     119                 * @since 3.11.0
     120                 */
     121                $this->cancelOrder($code);
    115122                return;
    116123            }
     
    119126            $coupon->delete();
    120127        }
     128    }
     129
     130    /**
     131     * Cancel an order containing an expired coupon.
     132     * Than coupon will be removed in `EWalletOrderModule` class.
     133     *
     134     * @todo Maybe to use the option to switch the possibility of cancel or not of the order.
     135     *
     136     * @since 3.11.0
     137     */
     138    public function cancelOrder($code): bool
     139    {
     140        global $wpdb;
     141        $pre = $wpdb->prefix;
     142        $order_ids = $wpdb->get_col(
     143            $wpdb->prepare(
     144                "SELECT order_id FROM {$pre}woocommerce_order_items WHERE order_item_type = 'coupon' AND order_item_name = %s",
     145                $code
     146            )
     147        );
     148
     149        $orders = [];
     150        if (!empty($order_ids)) {
     151            foreach ($order_ids as $order_id) {
     152                $orders[] = wc_get_order($order_id);
     153            }
     154        }
     155       
     156        if ( empty($orders) ) {
     157            return false;
     158        }
     159
     160        if ( $orders[0]->get_status() == OrderStatus::PENDING ) {
     161            /**
     162             * At the time the scheduler executes the code, the order may have the status "pending", thus the order is considered expired.
     163             */
     164            $orders[0]->update_status(OrderStatus::CANCELLED);
     165            return true;
     166        }
     167
     168        return false;
    121169    }
    122170
  • mlm-soft-integration/trunk/mlm-soft-integration.php

    r3378773 r3380390  
    44Plugin Name: MLM Soft Integration
    55Description: WP integration with mlm-soft.com cloud platform
    6 Version: 3.10.0
     6Version: 3.11.0
    77Author: MLM Soft Ltd.
    88Author URI: https://mlm-soft.com
Note: See TracChangeset for help on using the changeset viewer.