woocommerce_variation_prices filter runs only for the first hashed prices array loaded from the transient
This commit is contained in:
parent
8709d31f41
commit
35ff166a85
|
@ -258,15 +258,15 @@ class WC_Product_Variable extends WC_Product {
|
||||||
if ( empty( $this->prices_array[ $price_hash ] ) ) {
|
if ( empty( $this->prices_array[ $price_hash ] ) ) {
|
||||||
|
|
||||||
// Get value of transient
|
// Get value of transient
|
||||||
$this->prices_array = array_filter( (array) json_decode( strval( get_transient( $transient_name ) ), true ) );
|
$prices_array = array_filter( (array) json_decode( strval( get_transient( $transient_name ) ), true ) );
|
||||||
|
|
||||||
// If the product version has changed, reset cache
|
// If the product version has changed, reset cache
|
||||||
if ( empty( $this->prices_array['version'] ) || $this->prices_array['version'] !== WC_Cache_Helper::get_transient_version( 'product' ) ) {
|
if ( empty( $prices_array['version'] ) || $prices_array['version'] !== WC_Cache_Helper::get_transient_version( 'product' ) ) {
|
||||||
$this->prices_array = array( 'version' => WC_Cache_Helper::get_transient_version( 'product' ) );
|
$this->prices_array = array( 'version' => WC_Cache_Helper::get_transient_version( 'product' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the prices are not stored for this hash, generate them
|
// If the prices are not stored for this hash, generate them
|
||||||
if ( empty( $this->prices_array[ $price_hash ] ) ) {
|
if ( empty( $prices_array[ $price_hash ] ) ) {
|
||||||
$prices = array();
|
$prices = array();
|
||||||
$regular_prices = array();
|
$regular_prices = array();
|
||||||
$sale_prices = array();
|
$sale_prices = array();
|
||||||
|
@ -311,19 +311,19 @@ class WC_Product_Variable extends WC_Product {
|
||||||
asort( $regular_prices );
|
asort( $regular_prices );
|
||||||
asort( $sale_prices );
|
asort( $sale_prices );
|
||||||
|
|
||||||
$this->prices_array[ $price_hash ] = array(
|
$prices_array[ $price_hash ] = array(
|
||||||
'price' => $prices,
|
'price' => $prices,
|
||||||
'regular_price' => $regular_prices,
|
'regular_price' => $regular_prices,
|
||||||
'sale_price' => $sale_prices,
|
'sale_price' => $sale_prices,
|
||||||
);
|
);
|
||||||
|
|
||||||
set_transient( $transient_name, json_encode( $this->prices_array ), DAY_IN_SECONDS * 30 );
|
set_transient( $transient_name, json_encode( $prices_array ), DAY_IN_SECONDS * 30 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Give plugins one last chance to filter the variation prices array which has been generated.
|
* Give plugins one last chance to filter the variation prices array which has been generated.
|
||||||
*/
|
*/
|
||||||
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $this->prices_array[ $price_hash ], $this, $display );
|
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $prices_array[ $price_hash ], $this, $display );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue