woocommerce_use_legacy_get_variations_price_hash filter-hookWC 10.5.0

Filters whether to use the legacy callback serialization algorithm.

By default, WooCommerce will use the legacy algorithm to get the callback signatures for variation price hash calculation. This algorithm serializes the entire callback array as it comes from $wp_filter, which means that for callbacks that are class methods the entire object will be serialized, including the current values of the class variables. This implies that a change in these variables will change the price hash, even if they do not affect the price calculation.

This filter allows using CallbackUtil instead, which generates a more stable signature that does not depend on the internal state of objects, but only on the method names and class names. This results in a more consistent and reliable price hash, reducing unnecessary cache misses; but can cause compatibility issues with plugins that rely on the legacy behavior.

IMPORTANT: see also the documentation for the woocommerce_variation_prices_price

Usage

add_filter( 'woocommerce_use_legacy_get_variations_price_hash', 'wp_kama_woocommerce_use_legacy_get_variations_price_hash_filter', 10, 3 );

/**
 * Function for `woocommerce_use_legacy_get_variations_price_hash` filter-hook.
 * 
 * @param bool       $use_legacy  True to use the legacy algorithm (default), false to use CallbackUtil
 * @param WC_Product $product     The product object.
 * @param bool       $for_display If taxes should be calculated or not.
 *
 * @return bool
 */
function wp_kama_woocommerce_use_legacy_get_variations_price_hash_filter( $use_legacy, $product, $for_display ){

	// filter...
	return $use_legacy;
}
$use_legacy(true|false)
True to use the legacy algorithm (default), false to use CallbackUtil
$product(WC_Product)
The product object.
$for_display(true|false)
If taxes should be calculated or not.

Changelog

Since 10.5.0 Introduced.

Where the hook is called

WC_Product_Variable_Data_Store_CPT::get_price_hash()
woocommerce_use_legacy_get_variations_price_hash
woocommerce/includes/data-stores/class-wc-product-variable-data-store-cpt.php 619
$use_legacy_algorithm = apply_filters( 'woocommerce_use_legacy_get_variations_price_hash', true, $product, $for_display );

Where the hook is used in WooCommerce

Usage not found.