WC_API_Orders::set_item()protectedWC 2.2

Wrapper method to create/update order items

When updating, the item ID provided is checked to ensure it is associated with the order.

Метод класса: WC_API_Orders{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->set_item( $order, $item_type, $item, $action );
$order(\WC_Order) (обязательный)
order
$item_type(строка) (обязательный)
-
$item(массив) (обязательный)
item provided in the request body
$action(строка) (обязательный)
either 'create' or 'update'

Список изменений

С версии 2.2 Введена.

Код WC_API_Orders::set_item() WC 8.7.0

protected function set_item( $order, $item_type, $item, $action ) {
	global $wpdb;

	$set_method = "set_{$item_type}";

	// verify provided line item ID is associated with order
	if ( 'update' === $action ) {

		$result = $wpdb->get_row(
			$wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d",
			absint( $item['id'] ),
			absint( $order->get_id() )
		) );

		if ( is_null( $result ) ) {
			throw new WC_API_Exception( 'woocommerce_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 );
		}
	}

	$this->$set_method( $order, $item, $action );
}