woocommerce_variation_prices filter-hookWC 3.0.0

Filters the variation prices array for a variable product.

This filter gives plugins one last chance to modify the variation prices array which has been generated and will be stored locally to the class. This value may differ from the transient cache. It is filtered once before storing locally.

Usage

add_filter( 'woocommerce_variation_prices', 'wp_kama_woocommerce_variation_prices_filter', 10, 3 );

/**
 * Function for `woocommerce_variation_prices` filter-hook.
 * 
 * @param array      $prices_array Associative array of variation prices indexed by variation ID.
 * @param WC_Product $product      The variable product object.
 * @param bool       $for_display  Whether prices are being retrieved for display.
 *
 * @return array
 */
function wp_kama_woocommerce_variation_prices_filter( $prices_array, $product, $for_display ){

	// filter...
	return $prices_array;
}
$prices_array(array)

Associative array of variation prices indexed by variation ID.

  • price(array)
    Array of active prices (variation_id => price).

  • regular_price(array)
    Array of regular prices (variation_id => price).

  • sale_price(array)
    Array of sale prices (variation_id => price).
$product(WC_Product)
The variable product object.
$for_display(true|false)
Whether prices are being retrieved for display.

Changelog

Since 3.0.0 Introduced.

Where the hook is called

WC_Product_Variable_Data_Store_CPT::read_price_data()
woocommerce_variation_prices
woocommerce/includes/data-stores/class-wc-product-variable-data-store-cpt.php 444
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $transient_cached_prices_array[ $price_hash ], $product, $for_display );
woocommerce/includes/data-stores/class-wc-product-variable-data-store-cpt.php 447
$this->prices_array[ $opposite_price_hash ] = apply_filters( 'woocommerce_variation_prices', $transient_cached_prices_array[ $opposite_price_hash ], $product, ! $for_display );

Where the hook is used in WooCommerce

Usage not found.