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2.0-rc.1 3.0.9 6.2.0-rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / Overrides / OrderTraits.php
woocommerce / src / Admin / Overrides Last commit date
Order.php 2 months ago OrderRefund.php 5 days ago OrderTraits.php 5 days ago ThemeUpgrader.php 4 years ago ThemeUpgraderSkin.php 4 years ago
OrderTraits.php
136 lines
1 <?php
2 /**
3 * WC Admin Order Trait
4 *
5 * WC Admin Order Trait class that houses shared functionality across order and refund classes.
6 */
7
8 namespace Automattic\WooCommerce\Admin\Overrides;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Automattic\WooCommerce\Enums\OrderItemType;
13
14 /**
15 * OrderTraits class.
16 */
17 trait OrderTraits {
18 /**
19 * Calculate shipping amount for line item/product as a total shipping amount ratio based on quantity.
20 *
21 * @param WC_Order_Item $item Line item from order.
22 * @param int $order_items_count (optional) The number of order items in an order. This could be the remaining items left to refund.
23 * @param float $shipping_amount (optional) The shipping fee amount in an order. This could be the remaining shipping amount left to refund.
24 *
25 * @return float|int
26 */
27 public function get_item_shipping_amount( $item, $order_items_count = null, $shipping_amount = null ) {
28 // Shipping amount loosely based on woocommerce code in includes/admin/meta-boxes/views/html-order-item(s).php
29 // distributed simply based on number of line items.
30 $product_qty = $item->get_quantity( 'edit' );
31
32 // Use the passed order_items_count if provided, otherwise get the total number of items in the order.
33 // This is useful when calculating refunds for partial items in an order.
34 // For example, if 2 items are refunded from an order with 4 items. The remaining 2 items should have the shipping fee of the refunded items distributed to them.
35 $order_items = null !== $order_items_count ? $order_items_count : $this->get_item_count();
36
37 // Bail when there are no items to distribute the shipping across, to avoid dividing by zero.
38 // A loose check is used so a float 0.0 count is also treated as zero. Stores that allow decimal
39 // quantities (e.g. some Point of Sale plugins) make the item count a float, which a strict 0 === check would miss.
40 if ( ! $order_items ) {
41 return 0;
42 }
43
44 // Use the passed shipping_amount if provided, otherwise get the total shipping amount in the order.
45 // This is useful when calculating refunds for partial shipping in an order.
46 // For example, if $10 shipping is refunded from an order with $30 shipping, the remaining $20 should be distributed to the remaining items.
47 $total_shipping_amount = null !== $shipping_amount ? $shipping_amount : (float) $this->get_shipping_total();
48
49 return $total_shipping_amount / $order_items * $product_qty;
50 }
51
52 /**
53 * Calculate shipping tax amount for line item/product as a total shipping tax amount ratio based on quantity.
54 *
55 * Loosely based on code in includes/admin/meta-boxes/views/html-order-item(s).php.
56 *
57 * @todo If WC is currently not tax enabled, but it was before (or vice versa), would this work correctly?
58 *
59 * @param WC_Order_Item $item Line item from order.
60 * @param int $order_items_count (optional) The number of order items in an order. This could be the remaining items left to refund.
61 * @param float $shipping_tax_amount (optional) The shipping tax amount in an order. This could be the remaining shipping tax amount left to refund.
62 *
63 * @return float|int
64 */
65 public function get_item_shipping_tax_amount( $item, $order_items_count = null, $shipping_tax_amount = null ) {
66 // Use the passed order_items_count if provided, otherwise get the total number of items in the order.
67 // This is useful when calculating refunds for partial items in an order.
68 // For example, if 2 items are refunded from an order with 4 items. The remaining 2 items should have the shipping tax of the refunded items distributed to them.
69 $order_items = null !== $order_items_count ? $order_items_count : $this->get_item_count();
70
71 // Bail when there are no items to distribute the shipping tax across, to avoid dividing by zero.
72 // A loose check is used so a float 0.0 count is also treated as zero. Stores that allow decimal
73 // quantities (e.g. some Point of Sale plugins) make the item count a float, which a strict 0 === check would miss.
74 if ( ! $order_items ) {
75 return 0;
76 }
77
78 // Use the passed shipping_tax_amount if provided, otherwise initialize it to 0 and calculate the total shipping tax amount in the order.
79 // This is useful when calculating refunds for partial shipping tax in an order.
80 // For example, if $1 shipping tax is refunded from an order with $3 shipping tax, the remaining $2 should be distributed to the remaining items.
81 $total_shipping_tax_amount = $shipping_tax_amount ? $shipping_tax_amount : 0;
82
83 if ( null === $shipping_tax_amount ) {
84 $order_taxes = $this->get_taxes();
85 $line_items_shipping = $this->get_items( OrderItemType::SHIPPING );
86 foreach ( $line_items_shipping as $item_id => $shipping_item ) {
87 $tax_data = $shipping_item->get_taxes();
88 if ( $tax_data ) {
89 foreach ( $order_taxes as $tax_item ) {
90 $tax_item_id = $tax_item->get_rate_id();
91 $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? (float) $tax_data['total'][ $tax_item_id ] : 0;
92 $total_shipping_tax_amount += $tax_item_total;
93 }
94 }
95 }
96 }
97
98 $product_qty = $item->get_quantity( 'edit' );
99
100 return $total_shipping_tax_amount / $order_items * $product_qty;
101 }
102
103 /**
104 * Calculates coupon amount for specified line item/product.
105 *
106 * Coupon calculation based on woocommerce code in includes/admin/meta-boxes/views/html-order-item.php.
107 *
108 * @param WC_Order_Item $item Line item from order.
109 *
110 * @return float
111 */
112 public function get_item_coupon_amount( $item ) {
113 return floatval( $item->get_subtotal( 'edit' ) - $item->get_total( 'edit' ) );
114 }
115
116 /**
117 * Calculate cart tax amount for line item/product.
118 *
119 * @param WC_Order_Item $item Line item from order.
120 *
121 * @return float
122 */
123 public function get_item_cart_tax_amount( $item ) {
124 $order_taxes = $this->get_taxes();
125 $tax_data = $item->get_taxes();
126 $cart_tax_amount = 0.0;
127
128 foreach ( $order_taxes as $tax_item ) {
129 $tax_item_id = $tax_item->get_rate_id();
130 $cart_tax_amount += isset( $tax_data['total'][ $tax_item_id ] ) ? (float) $tax_data['total'][ $tax_item_id ] : 0;
131 }
132
133 return $cart_tax_amount;
134 }
135 }
136