Automattic\WooCommerce\StoreApi\Schemas\V1\Agentic

CheckoutSessionSchema::format_fulfillment_options_from_orderprotectedWC 1.0

Format fulfillment options from order.

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

Хуков нет.

Возвращает

Массив. Fulfillment options.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->format_fulfillment_options_from_order( $order );
$order(WC_Order) (обязательный)
Order object.

Код CheckoutSessionSchema::format_fulfillment_options_from_order() WC 10.5.0

protected function format_fulfillment_options_from_order( $order ) {
	$options          = [];
	$shipping_methods = $order->get_shipping_methods();

	foreach ( $shipping_methods as $item ) {
		$options[] = [
			'type'                   => FulfillmentType::SHIPPING,
			'id'                     => $item->get_method_id() . ':' . $item->get_instance_id(),
			'title'                  => $item->get_name(),
			'subtitle'               => null,
			'carrier'                => $item->get_method_id(),
			'earliest_delivery_time' => null,
			'latest_delivery_time'   => null,
			'subtotal'               => $this->amount_to_cents( $item->get_total() ),
			'tax'                    => $this->amount_to_cents( $item->get_total_tax() ),
			'total'                  => $this->amount_to_cents( $item->get_total() + $item->get_total_tax() ),
		];
	}

	return $options;
}