WC_Product_Variable_Data_Store_CPT::get_price_hash()protectedWC 3.0.0

Create unique cache key based on the tax location (affects displayed/cached prices), product version and active price filters. DEVELOPERS should filter this hash if offering conditional pricing to keep it unique.

Метод класса: WC_Product_Variable_Data_Store_CPT{}

Хуки из метода

Возвращает

Строку.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_price_hash( $product, $for_display );
$product(WC_Product) (обязательный) (передается по ссылке — &)
Product object.
$for_display(true|false)
If taxes should be calculated or not.
По умолчанию: false

Список изменений

С версии 3.0.0 Введена.

Код WC_Product_Variable_Data_Store_CPT::get_price_hash() WC 9.4.2

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

	$price_hash = array( false );

	if ( $for_display && wc_tax_enabled() ) {
		$price_hash = array(
			get_option( 'woocommerce_tax_display_shop', 'excl' ),
			WC_Tax::get_rates(),
			empty( WC()->customer ) ? false : WC()->customer->is_vat_exempt(),
		);
	}

	$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 ) ) );
}