Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/Override...
File: OrderTraits.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WC Admin Order Trait
[2] Fix | Delete
*
[3] Fix | Delete
* WC Admin Order Trait class that houses shared functionality across order and refund classes.
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\WooCommerce\Admin\Overrides;
[7] Fix | Delete
[8] Fix | Delete
defined( 'ABSPATH' ) || exit;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* OrderTraits class.
[12] Fix | Delete
*/
[13] Fix | Delete
trait OrderTraits {
[14] Fix | Delete
/**
[15] Fix | Delete
* Calculate shipping amount for line item/product as a total shipping amount ratio based on quantity.
[16] Fix | Delete
*
[17] Fix | Delete
* @param WC_Order_Item $item Line item from order.
[18] Fix | Delete
* @param int $order_items_count (optional) The number of order items in an order. This could be the remaining items left to refund.
[19] Fix | Delete
* @param float $shipping_amount (optional) The shipping fee amount in an order. This could be the remaining shipping amount left to refund.
[20] Fix | Delete
*
[21] Fix | Delete
* @return float|int
[22] Fix | Delete
*/
[23] Fix | Delete
public function get_item_shipping_amount( $item, $order_items_count = null, $shipping_amount = null ) {
[24] Fix | Delete
// Shipping amount loosely based on woocommerce code in includes/admin/meta-boxes/views/html-order-item(s).php
[25] Fix | Delete
// distributed simply based on number of line items.
[26] Fix | Delete
$product_qty = $item->get_quantity( 'edit' );
[27] Fix | Delete
[28] Fix | Delete
// Use the passed order_items_count if provided, otherwise get the total number of items in the order.
[29] Fix | Delete
// This is useful when calculating refunds for partial items in an order.
[30] Fix | Delete
// 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.
[31] Fix | Delete
$order_items = null !== $order_items_count ? $order_items_count : $this->get_item_count();
[32] Fix | Delete
[33] Fix | Delete
if ( 0 === $order_items ) {
[34] Fix | Delete
return 0;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
// Use the passed shipping_amount if provided, otherwise get the total shipping amount in the order.
[38] Fix | Delete
// This is useful when calculating refunds for partial shipping in an order.
[39] Fix | Delete
// For example, if $10 shipping is refunded from an order with $30 shipping, the remaining $20 should be distributed to the remaining items.
[40] Fix | Delete
$total_shipping_amount = null !== $shipping_amount ? $shipping_amount : (float) $this->get_shipping_total();
[41] Fix | Delete
[42] Fix | Delete
return $total_shipping_amount / $order_items * $product_qty;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Calculate shipping tax amount for line item/product as a total shipping tax amount ratio based on quantity.
[47] Fix | Delete
*
[48] Fix | Delete
* Loosely based on code in includes/admin/meta-boxes/views/html-order-item(s).php.
[49] Fix | Delete
*
[50] Fix | Delete
* @todo If WC is currently not tax enabled, but it was before (or vice versa), would this work correctly?
[51] Fix | Delete
*
[52] Fix | Delete
* @param WC_Order_Item $item Line item from order.
[53] Fix | Delete
* @param int $order_items_count (optional) The number of order items in an order. This could be the remaining items left to refund.
[54] Fix | Delete
* @param float $shipping_tax_amount (optional) The shipping tax amount in an order. This could be the remaining shipping tax amount left to refund.
[55] Fix | Delete
*
[56] Fix | Delete
* @return float|int
[57] Fix | Delete
*/
[58] Fix | Delete
public function get_item_shipping_tax_amount( $item, $order_items_count = null, $shipping_tax_amount = null ) {
[59] Fix | Delete
// Use the passed order_items_count if provided, otherwise get the total number of items in the order.
[60] Fix | Delete
// This is useful when calculating refunds for partial items in an order.
[61] Fix | Delete
// 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.
[62] Fix | Delete
$order_items = null !== $order_items_count ? $order_items_count : $this->get_item_count();
[63] Fix | Delete
[64] Fix | Delete
if ( 0 === $order_items ) {
[65] Fix | Delete
return 0;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Use the passed shipping_tax_amount if provided, otherwise initialize it to 0 and calculate the total shipping tax amount in the order.
[69] Fix | Delete
// This is useful when calculating refunds for partial shipping tax in an order.
[70] Fix | Delete
// 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.
[71] Fix | Delete
$total_shipping_tax_amount = $shipping_tax_amount ? $shipping_tax_amount : 0;
[72] Fix | Delete
[73] Fix | Delete
if ( null === $shipping_tax_amount ) {
[74] Fix | Delete
$order_taxes = $this->get_taxes();
[75] Fix | Delete
$line_items_shipping = $this->get_items( 'shipping' );
[76] Fix | Delete
foreach ( $line_items_shipping as $item_id => $shipping_item ) {
[77] Fix | Delete
$tax_data = $shipping_item->get_taxes();
[78] Fix | Delete
if ( $tax_data ) {
[79] Fix | Delete
foreach ( $order_taxes as $tax_item ) {
[80] Fix | Delete
$tax_item_id = $tax_item->get_rate_id();
[81] Fix | Delete
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? (float) $tax_data['total'][ $tax_item_id ] : 0;
[82] Fix | Delete
$total_shipping_tax_amount += $tax_item_total;
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
$product_qty = $item->get_quantity( 'edit' );
[89] Fix | Delete
[90] Fix | Delete
return $total_shipping_tax_amount / $order_items * $product_qty;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Calculates coupon amount for specified line item/product.
[95] Fix | Delete
*
[96] Fix | Delete
* Coupon calculation based on woocommerce code in includes/admin/meta-boxes/views/html-order-item.php.
[97] Fix | Delete
*
[98] Fix | Delete
* @param WC_Order_Item $item Line item from order.
[99] Fix | Delete
*
[100] Fix | Delete
* @return float
[101] Fix | Delete
*/
[102] Fix | Delete
public function get_item_coupon_amount( $item ) {
[103] Fix | Delete
return floatval( $item->get_subtotal( 'edit' ) - $item->get_total( 'edit' ) );
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Calculate cart tax amount for line item/product.
[108] Fix | Delete
*
[109] Fix | Delete
* @param WC_Order_Item $item Line item from order.
[110] Fix | Delete
*
[111] Fix | Delete
* @return float
[112] Fix | Delete
*/
[113] Fix | Delete
public function get_item_cart_tax_amount( $item ) {
[114] Fix | Delete
$order_taxes = $this->get_taxes();
[115] Fix | Delete
$tax_data = $item->get_taxes();
[116] Fix | Delete
$cart_tax_amount = 0.0;
[117] Fix | Delete
[118] Fix | Delete
foreach ( $order_taxes as $tax_item ) {
[119] Fix | Delete
$tax_item_id = $tax_item->get_rate_id();
[120] Fix | Delete
$cart_tax_amount += isset( $tax_data['total'][ $tax_item_id ] ) ? (float) $tax_data['total'][ $tax_item_id ] : 0;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
return $cart_tax_amount;
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function