WC_Product_Variable::get_variation_prices
Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
Метод класса: WC_Product_Variable{}
Хуков нет.
Возвращает
array. Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
Использование
$WC_Product_Variable = new WC_Product_Variable(); $WC_Product_Variable->get_variation_prices( $for_display );
- $for_display(true|false)
- If true, prices will be adapted for display based on the
woocommerce_tax_display_shopsetting (including or excluding taxes).
По умолчанию:false
Код WC_Product_Variable::get_variation_prices() WC Product Variable::get variation prices WC 11.3.0
public function get_variation_prices( $for_display = false ) {
/** @var array<string,array<int,float>> $prices */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$prices = $this->data_store->read_price_data( $this, $for_display );
if ( ! is_array( $prices ) ) {
return $prices;
}
// Performance note: loose != compares key/value pairs regardless of order, so a re-sort is only triggered when prices actually change.
$cache_key = $for_display ? 'for_display:1' : 'for_display:0';
if ( $this->variation_prices[ $cache_key ] != $prices ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
$this->variation_prices[ $cache_key ] = array_map( fn( $variation_prices ) => $this->sort_variation_prices( $variation_prices ), $prices );
}
return $this->variation_prices[ $cache_key ];
}