WC_Product_Variable_Data_Store_CPT::read_price_data
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.
Can be filtered by plugins which modify costs, but otherwise will include the raw meta costs unlike get_price() which runs costs through the woocommerce_get_price filter. This is to ensure modified prices are not cached, unless intended.
Method of the class: WC_Product_Variable_Data_Store_CPT{}
No Hooks.
Returns
array. of prices
Usage
$WC_Product_Variable_Data_Store_CPT = new WC_Product_Variable_Data_Store_CPT(); $WC_Product_Variable_Data_Store_CPT->read_price_data( $product, $for_display );
- $product(WC_Product) (required) (passed by reference — &)
- Product object.
- $for_display(true|false)
- If true, prices will be adapted for display based on the
woocommerce_tax_display_shopsetting (including or excluding taxes).
Default:false
Changelog
| Since 3.0.0 | Introduced. |
WC_Product_Variable_Data_Store_CPT::read_price_data() WC Product Variable Data Store CPT::read price data code WC 11.3.0
public function read_price_data( &$product, $for_display = false ) {
$hashes = $this->prime_price_data_cache( $product );
$hash = $for_display ? $hashes->hash_display : $hashes->hash_raw;
return array_key_exists( $hash, $this->prices_array ) ? $this->prices_array[ $hash ] : array();
}