WC_Product_Variable_Data_Store_CPT::get_price_hash( WC_Product $product, bool $for_display = false )

Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters.


Description Description

DEVELOPERS should filter this hash if offering conditional pricing to keep it unique.


Parameters Parameters

$product

(Required) Product object.

$for_display

(Optional) If taxes should be calculated or not.

Default value: false


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/data-stores/class-wc-product-variable-data-store-cpt.php

	protected function get_price_hash( &$product, $for_display = false ) {
		global $wp_filter;

		$price_hash   = $for_display && wc_tax_enabled() ? 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 ) {
			if ( ! empty( $wp_filter[ $filter_name ] ) ) {
				$price_hash[ $filter_name ] = array();

				foreach ( $wp_filter[ $filter_name ] as $priority => $callbacks ) {
					$price_hash[ $filter_name ][] = array_values( wp_list_pluck( $callbacks, 'function' ) );
				}
			}
		}

		return md5( wp_json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $product, $for_display ) ) );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.