WordPress at Your Fingertips
function is not described

WC_Gateway_Paypal_Request::line_items_valid() protected WC 1.0

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.

{} It's a 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.

Code of WC_Gateway_Paypal_Request::line_items_valid() WC 5.7.1

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;
}