Plugin Directory

Changeset 3249734


Ignore:
Timestamp:
03/03/2025 01:56:29 PM (13 months ago)
Author:
marknokes
Message:

Change sort order for order items

Location:
subscriptions-for-woo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • subscriptions-for-woo/tags/2.4.5/classes/PPSFWOO/class-ppsfwoo-order.php

    r3249341 r3249734  
    2121    public function __construct()
    2222    {
    23         add_filter('woocommerce_order_get_total', [$this, 'exclude_from_total'], 10, 2);
    24 
    2523        add_filter('woocommerce_order_get_subtotal', [$this, 'exclude_from_subtotal'], 10, 2);
    2624    }
    2725
    28     public function exclude_from_total($total, $order)
     26    public static function exclude_from_subtotal($subtotal, $order)
    2927    {
    3028        foreach ($order->get_items() as $item_id => $item)
     
    3331
    3432            if ($exclude_from_order_total === 'yes') {
    35 
    36                 $total -= $item->get_total();
    37 
    38             }
    39         }
    40 
    41         return $total;
    42     }
    43 
    44     public static function exclude_from_subtotal($subtotal, $order)
    45     {
    46         foreach ($order->get_items() as $item_id => $item)
    47         {
    48             $exclude_from_order_total = $item->get_meta('exclude_from_order_total')['value'] ?? '';
    49 
    50             if ($exclude_from_order_total === 'yes') {
    51 
     33               
    5234                $subtotal -= $item->get_subtotal();
    5335
     
    162144    private static function parse_order_items($order, $Subscriber)
    163145    {
     146        $items = [];
     147
     148        $payment_preferences = $Subscriber->plan->get_payment_preferences();
     149
    164150        $plan_id = $Subscriber->get_plan_id();
    165151
     
    179165
    180166                $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name);
    181 
    182                 $order->add_item($item);                
     167 
     168                $items[$sequence] = $item;             
    183169
    184170            } elseif (isset($cycle['pricing_scheme']['pricing_model'])) {
     
    198184                        $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name);
    199185
    200                         $order->add_item($item);
     186                        $items[$sequence] = $item;
    201187
    202188                    }
     
    205191        }
    206192
    207         $payment_preferences = $Subscriber->plan->get_payment_preferences();
    208 
    209193        if(isset($payment_preferences['setup_fee']['value']) && $payment_preferences['setup_fee']['value'] > 0) {
    210194
     
    213197            $fee = self::create_fee('One-time setup fee', $fee_amount);
    214198
    215             $order->add_item($fee);
     199            array_push($items, $fee);
     200
    216201        }
    217202
     
    224209            $product = $item->get_product();
    225210
    226             $is_product = $product && $product->exists();
    227 
    228             if (self::$has_trial && $is_product) {
     211            if (self::$has_trial && $product && $product->exists()) {
     212
     213                $item->set_subtotal(self::$line_item_price * self::$quantity);
    229214
    230215                $item->set_total(0);
     
    234219            }
    235220
    236             if(self::$tax_rate_data['tax_rate'] !== 0 && empty(self::$tax_rate_data['inclusive'])) {
    237 
    238                 $item->set_tax_class(self::$tax_rate_data['tax_rate_slug']);
    239 
     221            if(self::$tax_rate_data['tax_rate'] !== 0) {
     222
     223                if(empty(self::$tax_rate_data['inclusive'])) {
     224
     225                    $item->set_tax_class(self::$tax_rate_data['tax_rate_slug']);
     226
     227                } else {
     228
     229                    $item->set_tax_class("");
     230
     231                }
    240232            }
    241233           
    242234            $item->save();
     235        }
     236
     237        foreach($items as $sequence => $item)
     238        {
     239            $order->add_item($item);
    243240        }
    244241    }
  • subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-order.php

    r3249341 r3249734  
    2121    public function __construct()
    2222    {
    23         add_filter('woocommerce_order_get_total', [$this, 'exclude_from_total'], 10, 2);
    24 
    2523        add_filter('woocommerce_order_get_subtotal', [$this, 'exclude_from_subtotal'], 10, 2);
    2624    }
    2725
    28     public function exclude_from_total($total, $order)
     26    public static function exclude_from_subtotal($subtotal, $order)
    2927    {
    3028        foreach ($order->get_items() as $item_id => $item)
     
    3331
    3432            if ($exclude_from_order_total === 'yes') {
    35 
    36                 $total -= $item->get_total();
    37 
    38             }
    39         }
    40 
    41         return $total;
    42     }
    43 
    44     public static function exclude_from_subtotal($subtotal, $order)
    45     {
    46         foreach ($order->get_items() as $item_id => $item)
    47         {
    48             $exclude_from_order_total = $item->get_meta('exclude_from_order_total')['value'] ?? '';
    49 
    50             if ($exclude_from_order_total === 'yes') {
    51 
     33               
    5234                $subtotal -= $item->get_subtotal();
    5335
     
    162144    private static function parse_order_items($order, $Subscriber)
    163145    {
     146        $items = [];
     147
     148        $payment_preferences = $Subscriber->plan->get_payment_preferences();
     149
    164150        $plan_id = $Subscriber->get_plan_id();
    165151
     
    179165
    180166                $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name);
    181 
    182                 $order->add_item($item);                
     167 
     168                $items[$sequence] = $item;             
    183169
    184170            } elseif (isset($cycle['pricing_scheme']['pricing_model'])) {
     
    198184                        $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name);
    199185
    200                         $order->add_item($item);
     186                        $items[$sequence] = $item;
    201187
    202188                    }
     
    205191        }
    206192
    207         $payment_preferences = $Subscriber->plan->get_payment_preferences();
    208 
    209193        if(isset($payment_preferences['setup_fee']['value']) && $payment_preferences['setup_fee']['value'] > 0) {
    210194
     
    213197            $fee = self::create_fee('One-time setup fee', $fee_amount);
    214198
    215             $order->add_item($fee);
     199            array_push($items, $fee);
     200
    216201        }
    217202
     
    224209            $product = $item->get_product();
    225210
    226             $is_product = $product && $product->exists();
    227 
    228             if (self::$has_trial && $is_product) {
     211            if (self::$has_trial && $product && $product->exists()) {
     212
     213                $item->set_subtotal(self::$line_item_price * self::$quantity);
    229214
    230215                $item->set_total(0);
     
    234219            }
    235220
    236             if(self::$tax_rate_data['tax_rate'] !== 0 && empty(self::$tax_rate_data['inclusive'])) {
    237 
    238                 $item->set_tax_class(self::$tax_rate_data['tax_rate_slug']);
    239 
     221            if(self::$tax_rate_data['tax_rate'] !== 0) {
     222
     223                if(empty(self::$tax_rate_data['inclusive'])) {
     224
     225                    $item->set_tax_class(self::$tax_rate_data['tax_rate_slug']);
     226
     227                } else {
     228
     229                    $item->set_tax_class("");
     230
     231                }
    240232            }
    241233           
    242234            $item->save();
     235        }
     236
     237        foreach($items as $sequence => $item)
     238        {
     239            $order->add_item($item);
    243240        }
    244241    }
Note: See TracChangeset for help on using the changeset viewer.