Automattic\WooCommerce\StoreApi\Schemas\V1
ProductSchema::get_price_range
Get price range from certain product types.
Метод класса: ProductSchema{}
Хуков нет.
Возвращает
Объект|null.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_price_range( $product, $tax_display_mode );
- $product(WC_Product) (обязательный)
- Product instance.
- $tax_display_mode(строка)
- If returned prices are incl or excl of tax.
По умолчанию:''
Код ProductSchema::get_price_range() ProductSchema::get price range WC 11.0.1
protected function get_price_range( \WC_Product $product, $tax_display_mode = '' ) {
$tax_display_mode = $this->get_tax_display_mode( $tax_display_mode );
if ( $product->is_type( ProductType::VARIABLE ) ) {
$prices = $product->get_variation_prices( true );
if ( ! empty( $prices['price'] ) && ( min( $prices['price'] ) !== max( $prices['price'] ) ) ) {
return (object) [
'min_amount' => $this->prepare_money_response( min( $prices['price'] ), wc_get_price_decimals() ),
'max_amount' => $this->prepare_money_response( max( $prices['price'] ), wc_get_price_decimals() ),
];
}
}
if ( $product->is_type( ProductType::GROUPED ) ) {
$children = $product->get_visible_children();
$price_function = TaxDisplayMode::INCLUSIVE === $tax_display_mode ? 'wc_get_price_including_tax' : 'wc_get_price_excluding_tax';
foreach ( $children as $child ) {
if ( '' !== $child->get_price() ) {
$child_prices[] = $price_function( $child );
}
}
if ( ! empty( $child_prices ) ) {
return (object) [
'min_amount' => $this->prepare_money_response( min( $child_prices ), wc_get_price_decimals() ),
'max_amount' => $this->prepare_money_response( max( $child_prices ), wc_get_price_decimals() ),
];
}
}
return null;
}