wc_get_cart_item_data_hash( WC_Product $product )

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


Description Description

The woocommerce_cart_item_data_to_validate filter can be used to add custom properties.


Parameters Parameters

$product

(Required) Product object.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/wc-cart-functions.php

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


Top ↑

User Contributed Notes User Contributed Notes

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