WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Schemas

ProductSchema::prepare_product_price_response() protected WC 1.0

Get an array of pricing data.

{} It's a method of the class: ProductSchema{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_product_price_response( $product, $tax_display_mode );
$product(WC_Product) (required)
Product instance.
$tax_display_mode(string)
If returned prices are incl or excl of tax.
Default: ''

Code of ProductSchema::prepare_product_price_response() WC 5.8.0

protected function prepare_product_price_response( \WC_Product $product, $tax_display_mode = '' ) {
	$prices           = [];
	$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
	$price_function   = $this->get_price_function_from_tax_display_mode( $tax_display_mode );

	// If we have a variable product, get the price from the variations (this will use the min value).
	if ( $product->is_type( 'variable' ) ) {
		$regular_price = $product->get_variation_regular_price();
		$sale_price    = $product->get_variation_sale_price();
	} else {
		$regular_price = $product->get_regular_price();
		$sale_price    = $product->get_sale_price();
	}

	$prices['price']         = $this->prepare_money_response( $price_function( $product ), wc_get_price_decimals() );
	$prices['regular_price'] = $this->prepare_money_response( $price_function( $product, [ 'price' => $regular_price ] ), wc_get_price_decimals() );
	$prices['sale_price']    = $this->prepare_money_response( $price_function( $product, [ 'price' => $sale_price ] ), wc_get_price_decimals() );
	$prices['price_range']   = $this->get_price_range( $product, $tax_display_mode );

	return $this->prepare_currency_response( $prices );
}