WC_REST_Orders_V1_Controller::prepare_shipping_lines()protectedWC 1.0

Create or update an order shipping method.

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

Хуков нет.

Возвращает

WC_Order_Item_Shipping.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->prepare_shipping_lines( $posted, $action );
$posted (обязательный)
-
$action(строка) (обязательный)
'create' to add shipping or 'update' to update it.

Код WC_REST_Orders_V1_Controller::prepare_shipping_lines() WC 8.7.0

protected function prepare_shipping_lines( $posted, $action ) {
	$item = new WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' );

	if ( 'create' === $action ) {
		if ( empty( $posted['method_id'] ) ) {
			throw new WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 );
		}
	}

	$this->maybe_set_item_props( $item, array( 'method_id', 'method_title', 'total' ), $posted );

	return $item;
}