parent
0ca68ff51e
commit
c3623a9967
|
@ -74,11 +74,11 @@ class WC_Product_Variable extends WC_Product {
|
|||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param bool $include_taxes Should taxes be included in the prices.
|
||||
* @param bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||
* @return array Array of RAW prices, regular prices, and sale prices with keys set to variation ID.
|
||||
*/
|
||||
public function get_variation_prices( $include_taxes = false ) {
|
||||
$prices = $this->data_store->read_price_data( $this, $include_taxes );
|
||||
public function get_variation_prices( $for_display = false ) {
|
||||
$prices = $this->data_store->read_price_data( $this, $for_display );
|
||||
|
||||
foreach ( $prices as $price_key => $variation_prices ) {
|
||||
$prices[ $price_key ] = $this->sort_variation_prices( $variation_prices );
|
||||
|
@ -90,40 +90,40 @@ class WC_Product_Variable extends WC_Product {
|
|||
/**
|
||||
* Get the min or max variation regular price.
|
||||
*
|
||||
* @param string $min_or_max Min or max price.
|
||||
* @param boolean $include_taxes Should the price include taxes?
|
||||
* @param string $min_or_max Min or max price.
|
||||
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||
* @return string
|
||||
*/
|
||||
public function get_variation_regular_price( $min_or_max = 'min', $include_taxes = false ) {
|
||||
$prices = $this->get_variation_prices( $include_taxes );
|
||||
public function get_variation_regular_price( $min_or_max = 'min', $for_display = false ) {
|
||||
$prices = $this->get_variation_prices( $for_display );
|
||||
$price = 'min' === $min_or_max ? current( $prices['regular_price'] ) : end( $prices['regular_price'] );
|
||||
return apply_filters( 'woocommerce_get_variation_regular_price', $price, $this, $min_or_max, $include_taxes );
|
||||
return apply_filters( 'woocommerce_get_variation_regular_price', $price, $this, $min_or_max, $for_display );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the min or max variation sale price.
|
||||
*
|
||||
* @param string $min_or_max Min or max price.
|
||||
* @param boolean $include_taxes Should the price include taxes?
|
||||
* @param string $min_or_max Min or max price.
|
||||
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||
* @return string
|
||||
*/
|
||||
public function get_variation_sale_price( $min_or_max = 'min', $include_taxes = false ) {
|
||||
$prices = $this->get_variation_prices( $include_taxes );
|
||||
public function get_variation_sale_price( $min_or_max = 'min', $for_display = false ) {
|
||||
$prices = $this->get_variation_prices( $for_display );
|
||||
$price = 'min' === $min_or_max ? current( $prices['sale_price'] ) : end( $prices['sale_price'] );
|
||||
return apply_filters( 'woocommerce_get_variation_sale_price', $price, $this, $min_or_max, $include_taxes );
|
||||
return apply_filters( 'woocommerce_get_variation_sale_price', $price, $this, $min_or_max, $for_display );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the min or max variation (active) price.
|
||||
*
|
||||
* @param string $min_or_max Min or max price.
|
||||
* @param boolean $include_taxes Should the price include taxes?
|
||||
* @param string $min_or_max Min or max price.
|
||||
* @param boolean $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||
* @return string
|
||||
*/
|
||||
public function get_variation_price( $min_or_max = 'min', $include_taxes = false ) {
|
||||
$prices = $this->get_variation_prices( $include_taxes );
|
||||
public function get_variation_price( $min_or_max = 'min', $for_display = false ) {
|
||||
$prices = $this->get_variation_prices( $for_display );
|
||||
$price = 'min' === $min_or_max ? current( $prices['price'] ) : end( $prices['price'] );
|
||||
return apply_filters( 'woocommerce_get_variation_price', $price, $this, $min_or_max, $include_taxes );
|
||||
return apply_filters( 'woocommerce_get_variation_price', $price, $this, $min_or_max, $for_display );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -234,10 +234,10 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
*
|
||||
* @since 3.0.0
|
||||
* @param WC_Product $product Product object.
|
||||
* @param bool $include_taxes If taxes should be calculated or not.
|
||||
* @param bool $for_display If true, prices will be adapted for display based on the `woocommerce_tax_display_shop` setting (including or excluding taxes).
|
||||
* @return array of prices
|
||||
*/
|
||||
public function read_price_data( &$product, $include_taxes = false ) {
|
||||
public function read_price_data( &$product, $for_display = false ) {
|
||||
|
||||
/**
|
||||
* Transient name for storing prices for this product (note: Max transient length is 45)
|
||||
|
@ -246,7 +246,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
*/
|
||||
$transient_name = 'wc_var_prices_' . $product->get_id();
|
||||
|
||||
$price_hash = $this->get_price_hash( $product, $include_taxes );
|
||||
$price_hash = $this->get_price_hash( $product, $for_display );
|
||||
|
||||
/**
|
||||
* $this->prices_array is an array of values which may have been modified from what is stored in transients - this may not match $transient_cached_prices_array.
|
||||
|
@ -283,7 +283,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
}
|
||||
|
||||
// If we are getting prices for display, we need to account for taxes.
|
||||
if ( $include_taxes ) {
|
||||
if ( $for_display ) {
|
||||
if ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) {
|
||||
$price = '' === $price ? '' : wc_get_price_including_tax( $variation, array( 'qty' => 1, 'price' => $price ) );
|
||||
$regular_price = '' === $regular_price ? '' : wc_get_price_including_tax( $variation, array( 'qty' => 1, 'price' => $regular_price ) );
|
||||
|
@ -307,14 +307,14 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
'sale_price' => $sale_prices,
|
||||
);
|
||||
|
||||
set_transient( $transient_name, json_encode( $transient_cached_prices_array ), DAY_IN_SECONDS * 30 );
|
||||
set_transient( $transient_name, wp_json_encode( $transient_cached_prices_array ), DAY_IN_SECONDS * 30 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Give plugins one last chance to filter the variation prices array which has been generated and store locally to the class.
|
||||
* This value may differ from the transient cache. It is filtered once before storing locally.
|
||||
*/
|
||||
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $transient_cached_prices_array[ $price_hash ], $product, $include_taxes );
|
||||
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $transient_cached_prices_array[ $price_hash ], $product, $for_display );
|
||||
}
|
||||
return $this->prices_array[ $price_hash ];
|
||||
}
|
||||
|
@ -325,13 +325,13 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
*
|
||||
* @since 3.0.0
|
||||
* @param WC_Product $product Product object.
|
||||
* @param bool $include_taxes If taxes should be calculated or not.
|
||||
* @param bool $for_display If taxes should be calculated or not.
|
||||
* @return string
|
||||
*/
|
||||
protected function get_price_hash( &$product, $include_taxes = false ) {
|
||||
protected function get_price_hash( &$product, $for_display = false ) {
|
||||
global $wp_filter;
|
||||
|
||||
$price_hash = $include_taxes ? array( get_option( 'woocommerce_tax_display_shop', 'excl' ), WC_Tax::get_rates() ) : array( false );
|
||||
$price_hash = $for_display ? array( get_option( 'woocommerce_tax_display_shop', 'excl' ), WC_Tax::get_rates() ) : array( false );
|
||||
$filter_names = array( 'woocommerce_variation_prices_price', 'woocommerce_variation_prices_regular_price', 'woocommerce_variation_prices_sale_price' );
|
||||
|
||||
foreach ( $filter_names as $filter_name ) {
|
||||
|
@ -345,7 +345,7 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
}
|
||||
|
||||
$price_hash[] = WC_Cache_Helper::get_transient_version( 'product' );
|
||||
$price_hash = md5( json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $product, $include_taxes ) ) );
|
||||
$price_hash = md5( json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $product, $for_display ) ) );
|
||||
|
||||
return $price_hash;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue