WC_Gateway_Paypal_Request::line_items_valid()
Check if the order has valid line items to use for PayPal request.
The line items are invalid in case of mismatch in totals or if any amount < 0.
Method of the class: WC_Gateway_Paypal_Request{}
No Hooks.
Return
true|false
.
Usage
// protected - for code of main (parent) or child class $result = $this->line_items_valid( $order );
- $order(WC_Order) (required)
- Order to be examined.
WC_Gateway_Paypal_Request::line_items_valid() WC Gateway Paypal Request::line items valid code WC 8.7.0
protected function line_items_valid( $order ) { $negative_item_amount = false; $calculated_total = 0; // Products. foreach ( $order->get_items( array( 'line_item', 'fee' ) ) as $item ) { if ( 'fee' === $item['type'] ) { $item_line_total = $this->number_format( $item['line_total'], $order ); $calculated_total += $item_line_total; } else { $item_line_total = $this->number_format( $order->get_item_subtotal( $item, false ), $order ); $calculated_total += $item_line_total * $item->get_quantity(); } if ( $item_line_total < 0 ) { $negative_item_amount = true; } } $mismatched_totals = $this->number_format( $calculated_total + $order->get_total_tax() + $this->round( $order->get_shipping_total(), $order ) - $this->round( $order->get_total_discount(), $order ), $order ) !== $this->number_format( $order->get_total(), $order ); return ! $negative_item_amount && ! $mismatched_totals; }