wc_get_cart_item_data_hash()WC 1.0

Gets a hash of important product data that when changed should cause cart items to be invalidated.

The woocommerce_cart_item_data_to_validate filter can be used to add custom properties.

Хуки из функции

Возвращает

Строку.

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

wc_get_cart_item_data_hash( $product );
$product(WC_Product) (обязательный)
Product object.

Код wc_get_cart_item_data_hash() WC 8.7.0

function wc_get_cart_item_data_hash( $product ) {
	return md5(
		wp_json_encode(
			apply_filters(
				'woocommerce_cart_item_data_to_validate',
				array(
					'type'       => $product->get_type(),
					'attributes' => 'variation' === $product->get_type() ? $product->get_variation_attributes() : '',
				),
				$product
			)
		)
	);
}