Automattic\WooCommerce\StoreApi\Schemas\V1

ShopperListItemSchema::get_pricesprivateWC 1.0

Compute live prices for the saved item.

We don't extend ProductSchema because saved items aren't products. The shape here is a thin subset of cart-item prices.

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

Хуков нет.

Возвращает

Массив.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_prices( $product ): array;
$product(WC_Product) (обязательный)
Live product instance.

Код ShopperListItemSchema::get_prices() WC 11.0.1

private function get_prices( \WC_Product $product ): array {
	$decimals      = wc_get_price_decimals();
	$regular_price = $product->get_regular_price();
	$sale_price    = $product->get_sale_price();
	$current_price = $product->get_price();

	return $this->prepare_currency_response(
		array(
			'price'         => $this->prepare_money_response( $current_price, $decimals ),
			'regular_price' => $this->prepare_money_response( '' === $regular_price ? $current_price : $regular_price, $decimals ),
			'sale_price'    => '' === $sale_price ? '' : $this->prepare_money_response( $sale_price, $decimals ),
		)
	);
}