Changeset 3249734
- Timestamp:
- 03/03/2025 01:56:29 PM (13 months ago)
- Location:
- subscriptions-for-woo
- Files:
-
- 2 edited
-
tags/2.4.5/classes/PPSFWOO/class-ppsfwoo-order.php (modified) (9 diffs)
-
trunk/classes/PPSFWOO/class-ppsfwoo-order.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
subscriptions-for-woo/tags/2.4.5/classes/PPSFWOO/class-ppsfwoo-order.php
r3249341 r3249734 21 21 public function __construct() 22 22 { 23 add_filter('woocommerce_order_get_total', [$this, 'exclude_from_total'], 10, 2);24 25 23 add_filter('woocommerce_order_get_subtotal', [$this, 'exclude_from_subtotal'], 10, 2); 26 24 } 27 25 28 public function exclude_from_total($total, $order)26 public static function exclude_from_subtotal($subtotal, $order) 29 27 { 30 28 foreach ($order->get_items() as $item_id => $item) … … 33 31 34 32 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 52 34 $subtotal -= $item->get_subtotal(); 53 35 … … 162 144 private static function parse_order_items($order, $Subscriber) 163 145 { 146 $items = []; 147 148 $payment_preferences = $Subscriber->plan->get_payment_preferences(); 149 164 150 $plan_id = $Subscriber->get_plan_id(); 165 151 … … 179 165 180 166 $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name); 181 182 $ order->add_item($item);167 168 $items[$sequence] = $item; 183 169 184 170 } elseif (isset($cycle['pricing_scheme']['pricing_model'])) { … … 198 184 $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name); 199 185 200 $ order->add_item($item);186 $items[$sequence] = $item; 201 187 202 188 } … … 205 191 } 206 192 207 $payment_preferences = $Subscriber->plan->get_payment_preferences();208 209 193 if(isset($payment_preferences['setup_fee']['value']) && $payment_preferences['setup_fee']['value'] > 0) { 210 194 … … 213 197 $fee = self::create_fee('One-time setup fee', $fee_amount); 214 198 215 $order->add_item($fee); 199 array_push($items, $fee); 200 216 201 } 217 202 … … 224 209 $product = $item->get_product(); 225 210 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); 229 214 230 215 $item->set_total(0); … … 234 219 } 235 220 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 } 240 232 } 241 233 242 234 $item->save(); 235 } 236 237 foreach($items as $sequence => $item) 238 { 239 $order->add_item($item); 243 240 } 244 241 } -
subscriptions-for-woo/trunk/classes/PPSFWOO/class-ppsfwoo-order.php
r3249341 r3249734 21 21 public function __construct() 22 22 { 23 add_filter('woocommerce_order_get_total', [$this, 'exclude_from_total'], 10, 2);24 25 23 add_filter('woocommerce_order_get_subtotal', [$this, 'exclude_from_subtotal'], 10, 2); 26 24 } 27 25 28 public function exclude_from_total($total, $order)26 public static function exclude_from_subtotal($subtotal, $order) 29 27 { 30 28 foreach ($order->get_items() as $item_id => $item) … … 33 31 34 32 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 52 34 $subtotal -= $item->get_subtotal(); 53 35 … … 162 144 private static function parse_order_items($order, $Subscriber) 163 145 { 146 $items = []; 147 148 $payment_preferences = $Subscriber->plan->get_payment_preferences(); 149 164 150 $plan_id = $Subscriber->get_plan_id(); 165 151 … … 179 165 180 166 $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name); 181 182 $ order->add_item($item);167 168 $items[$sequence] = $item; 183 169 184 170 } elseif (isset($cycle['pricing_scheme']['pricing_model'])) { … … 198 184 $item = self::create_line_item($cycle, $price * self::$quantity, $sequence, $name); 199 185 200 $ order->add_item($item);186 $items[$sequence] = $item; 201 187 202 188 } … … 205 191 } 206 192 207 $payment_preferences = $Subscriber->plan->get_payment_preferences();208 209 193 if(isset($payment_preferences['setup_fee']['value']) && $payment_preferences['setup_fee']['value'] > 0) { 210 194 … … 213 197 $fee = self::create_fee('One-time setup fee', $fee_amount); 214 198 215 $order->add_item($fee); 199 array_push($items, $fee); 200 216 201 } 217 202 … … 224 209 $product = $item->get_product(); 225 210 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); 229 214 230 215 $item->set_total(0); … … 234 219 } 235 220 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 } 240 232 } 241 233 242 234 $item->save(); 235 } 236 237 foreach($items as $sequence => $item) 238 { 239 $order->add_item($item); 243 240 } 244 241 }
Note: See TracChangeset
for help on using the changeset viewer.