woocommerce_variation_prices_array filter-hookWC 3.6.0

Filter the variation prices array before storing in transient cache.

This filter allows developers to modify the variation prices array for each variation during the price calculation process. It's called for each variation individually and can be used to add custom pricing data or modify existing prices.

Usage

add_filter( 'woocommerce_variation_prices_array', 'wp_kama_woocommerce_variation_prices_array_filter', 10, 3 );

/**
 * Function for `woocommerce_variation_prices_array` filter-hook.
 * 
 * @param array      $prices_array The prices array being built. Contains 'price', 'regular_price', and 'sale_price' keys.
 * @param WC_Product $variation    The variation product object.
 * @param bool       $for_display  Whether prices are for display (with tax adjustments) or for calculations.
 *
 * @return array
 */
function wp_kama_woocommerce_variation_prices_array_filter( $prices_array, $variation, $for_display ){

	// filter...
	return $prices_array;
}
$prices_array(array)
The prices array being built. Contains 'price', 'regular_price', and 'sale_price' keys.
$variation(WC_Product)
The variation product object.
$for_display(true|false)
Whether prices are for display (with tax adjustments) or for calculations.

Changelog

Since 3.6.0 Introduced.

Where the hook is called

WC_Product_Variable_Data_Store_CPT::read_price_data()
woocommerce_variation_prices_array
woocommerce/includes/data-stores/class-wc-product-variable-data-store-cpt.php 490
$prices_array = apply_filters( 'woocommerce_variation_prices_array', $prices_array, $variation, $for_display );
woocommerce/includes/data-stores/class-wc-product-variable-data-store-cpt.php 497
$opposite_prices_array      = apply_filters( 'woocommerce_variation_prices_array', $original_prices_array, $variation, ! $for_display );

Where the hook is used in WooCommerce

Usage not found.