Automattic\WooCommerce\Internal\ProductFeed\Mapping
UcpProductMapper::build_list_price_range
Build the list price range from the variants built for the product.
Spans every variant's regular price, but only when some variant is genuinely discounted; a variant carries list_price only in that case.
Метод класса: UcpProductMapper{}
Хуков нет.
Возвращает
array|null.
Использование
// private - только в коде основоного (родительского) класса $result = $this->build_list_price_range( $variants );
- $variants(массив) (обязательный)
- Built variants.
Код UcpProductMapper::build_list_price_range() UcpProductMapper::build list price range WC 11.3.0
private function build_list_price_range( array $variants ) {
$has_discount = false;
$regular = array();
foreach ( $variants as $variant ) {
if ( isset( $variant['list_price'] ) ) {
$has_discount = true;
$regular[] = $variant['list_price']['amount'];
} else {
$regular[] = $variant['price']['amount'];
}
}
if ( ! $has_discount || empty( $regular ) ) {
return null;
}
$currency = $variants[0]['price']['currency'];
return array(
'min' => $this->price( min( $regular ), $currency ),
'max' => $this->price( max( $regular ), $currency ),
);
}