Automattic\WooCommerce\StoreApi\Schemas\V1
ProductSchema::prepare_product_price_response
Get an array of pricing data.
Метод класса: ProductSchema{}
Хуков нет.
Возвращает
array.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->prepare_product_price_response( $product, $tax_display_mode );
- $product(WC_Product) (обязательный)
- Product instance.
- $tax_display_mode(строка)
- If returned prices are incl or excl of tax.
По умолчанию:''
Код ProductSchema::prepare_product_price_response() ProductSchema::prepare product price response WC 11.1.1
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 );
$price_decimals = wc_get_price_decimals();
// If we have a variable product, get the price from the variations (this will use the min value).
if ( $product->is_type( ProductType::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 ), $price_decimals );
$prices['regular_price'] = $this->prepare_money_response( $price_function( $product, [ 'price' => $regular_price ] ), $price_decimals );
$prices['sale_price'] = $this->prepare_money_response( $price_function( $product, [ 'price' => $sale_price ] ), $price_decimals );
$prices['price_range'] = $this->get_price_range( $product, $tax_display_mode );
return $this->prepare_currency_response( $prices );
}