�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`� 0x0x
PHP 8.1.34
Preview: ProductVersionStringInvalidator.php Size: 20.41 KB
/home2/astrociv/www/rudraraksham.com/wp-content/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php
<?php

declare( strict_types=1 );

namespace Automattic\WooCommerce\Internal\Caches;

use Automattic\WooCommerce\Internal\Features\FeaturesController;

/**
 * Product version string invalidation handler.
 *
 * This class provides an 'invalidate' method that will invalidate
 * the version string for a given product, which in turn invalidates
 * any cached REST API responses containing that product.
 */
class ProductVersionStringInvalidator {

	/**
	 * Default cache TTL in seconds for term/taxonomy entity lookups.
	 */
	const DEFAULT_TAXONOMY_LOOKUP_CACHE_TTL = 300;

	/**
	 * Initialize the invalidator and register hooks.
	 *
	 * Hooks are only registered when both conditions are met:
	 * - The REST API caching feature is enabled
	 * - The backend caching setting is active
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	final public function init(): void {
		// We can't use FeaturesController::feature_is_enabled at this point
		// (before the 'init' action is triggered) because that would cause
		// "Translation loading for the woocommerce domain was triggered too early" warnings.
		if ( 'yes' !== get_option( 'woocommerce_feature_rest_api_caching_enabled' ) ) {
			return;
		}

		if ( 'yes' === get_option( 'woocommerce_rest_api_enable_backend_caching', 'no' ) ) {
			$this->register_hooks();
		}
	}

	/**
	 * Register all product-related hooks.
	 *
	 * Registers ALL hooks (WordPress and WooCommerce) to ensure comprehensive coverage.
	 * This handles both standard data stores and custom implementations, as well as
	 * third-party plugins that may use direct SQL with manual hook firing.
	 *
	 * @return void
	 */
	private function register_hooks(): void {
		// WordPress post hooks for products.
		add_action( 'save_post_product', array( $this, 'handle_save_post_product' ), 10, 1 );
		add_action( 'delete_post', array( $this, 'handle_delete_post' ), 10, 2 );
		add_action( 'trashed_post', array( $this, 'handle_trashed_post' ), 10, 1 );
		add_action( 'untrashed_post', array( $this, 'handle_untrashed_post' ), 10, 1 );
		add_action( 'transition_post_status', array( $this, 'handle_transition_post_status' ), 10, 3 );

		// WooCommerce CRUD hooks for products.
		add_action( 'woocommerce_new_product', array( $this, 'handle_woocommerce_new_product' ), 10, 1 );
		add_action( 'woocommerce_update_product', array( $this, 'handle_woocommerce_update_product' ), 10, 1 );
		add_action( 'woocommerce_before_delete_product', array( $this, 'handle_woocommerce_before_delete_product' ), 10, 1 );
		add_action( 'woocommerce_trash_product', array( $this, 'handle_woocommerce_trash_product' ), 10, 1 );

		// WooCommerce CRUD hooks for variations.
		add_action( 'woocommerce_new_product_variation', array( $this, 'handle_woocommerce_new_product_variation' ), 10, 2 );
		add_action( 'woocommerce_update_product_variation', array( $this, 'handle_woocommerce_update_product_variation' ), 10, 2 );
		add_action( 'woocommerce_before_delete_product_variation', array( $this, 'handle_woocommerce_before_delete_product_variation' ), 10, 1 );
		add_action( 'woocommerce_trash_product_variation', array( $this, 'handle_woocommerce_trash_product_variation' ), 10, 1 );

		// SQL-level operation hooks.
		add_action( 'woocommerce_updated_product_stock', array( $this, 'handle_woocommerce_updated_product_stock' ), 10, 1 );
		add_action( 'woocommerce_updated_product_price', array( $this, 'handle_woocommerce_updated_product_price' ), 10, 1 );
		add_action( 'woocommerce_updated_product_sales', array( $this, 'handle_woocommerce_updated_product_sales' ), 10, 1 );

		// Attribute-related hooks (only for CPT data store).
		// These hooks use direct SQL queries that assume CPT storage.
		if ( $this->is_using_cpt_data_store() ) {
			add_action( 'woocommerce_attribute_updated', array( $this, 'handle_woocommerce_attribute_updated' ), 10, 2 );
			add_action( 'woocommerce_attribute_deleted', array( $this, 'handle_woocommerce_attribute_deleted' ), 10, 3 );
			add_action( 'woocommerce_updated_product_attribute_summary', array( $this, 'handle_woocommerce_updated_product_attribute_summary' ), 10, 1 );
			add_action( 'edited_term', array( $this, 'handle_edited_term' ), 10, 3 );
		}
	}

	/**
	 * Check if the product data store is CPT-based.
	 *
	 * @return bool True if using CPT data store, false otherwise.
	 */
	private function is_using_cpt_data_store(): bool {
		$data_store = \WC_Data_Store::load( 'product' );
		return $data_store->get_current_class_name() === 'WC_Product_Data_Store_CPT';
	}

	/**
	 * Handle the save_post_product hook.
	 *
	 * @param int $post_id The post ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_save_post_product( $post_id ): void {
		$post_id = (int) $post_id;

		if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
			return;
		}

		$this->invalidate( $post_id );
	}

	/**
	 * Handle the delete_post hook.
	 *
	 * @param int           $post_id The post ID.
	 * @param \WP_Post|null $post The post object, or null if not provided.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_delete_post( $post_id, $post = null ): void {
		$post_id = (int) $post_id;

		if ( ! $post instanceof \WP_Post ) {
			$post = get_post( $post_id );
		}

		if ( ! $post ) {
			return;
		}

		if ( 'product_variation' === $post->post_type ) {
			$parent_id = (int) $post->post_parent;
			$this->invalidate_variation_and_parent( $post_id, $parent_id );
			$this->invalidate_variations_list( $parent_id );
			$this->invalidate_variation_parent_cache( $post_id );
		} elseif ( 'product' === $post->post_type ) {
			$this->invalidate( $post_id );
			$this->invalidate_products_list();
		}
	}

	/**
	 * Handle the trashed_post hook.
	 *
	 * @param int $post_id The post ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_trashed_post( $post_id ): void {
		$this->handle_trashed_or_untrashed_post( (int) $post_id );
	}

	/**
	 * Handle the untrashed_post hook.
	 *
	 * @param int $post_id The post ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_untrashed_post( $post_id ): void {
		$this->handle_trashed_or_untrashed_post( (int) $post_id );
	}

	/**
	 * Handle the transition_post_status hook.
	 *
	 * Invalidates the product list version string when a product or variation
	 * changes status, as this may affect which products appear in collection endpoints.
	 *
	 * @param string   $new_status The new post status.
	 * @param string   $old_status The old post status.
	 * @param \WP_Post $post       The post object.
	 *
	 * @return void
	 *
	 * @since 10.6.0
	 *
	 * @internal
	 */
	public function handle_transition_post_status( $new_status, $old_status, $post ): void {
		if ( ! $post instanceof \WP_Post ) {
			return;
		}

		if ( $new_status === $old_status ) {
			return;
		}

		if ( 'product' === $post->post_type ) {
			$this->invalidate_products_list();
		} elseif ( 'product_variation' === $post->post_type ) {
			$this->invalidate_variations_list( (int) $post->post_parent );
		}
	}

	/**
	 * Handle the trashed_post and untrashed_post hooks.
	 *
	 * @param int $post_id The post ID.
	 *
	 * @return void
	 */
	private function handle_trashed_or_untrashed_post( int $post_id ): void {
		$post = get_post( $post_id );

		if ( ! $post ) {
			return;
		}

		if ( 'product_variation' === $post->post_type ) {
			$parent_id = (int) $post->post_parent;
			$this->invalidate_variation_and_parent( $post_id, $parent_id );
			$this->invalidate_variations_list( $parent_id );
			$this->invalidate_variation_parent_cache( $post_id );
		} elseif ( 'product' === $post->post_type ) {
			$this->invalidate( $post_id );
			$this->invalidate_products_list();
		}
	}

	/**
	 * Handle the woocommerce_new_product_variation hook.
	 *
	 * @param int         $variation_id The variation ID.
	 * @param \WC_Product $variation The variation object.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_new_product_variation( $variation_id, $variation ): void {
		$variation_id = (int) $variation_id;
		$parent_id    = $variation instanceof \WC_Product ? $variation->get_parent_id() : null;
		$this->invalidate_variation_and_parent( $variation_id, $parent_id );
		$this->invalidate_variations_list( $parent_id );
	}

	/**
	 * Handle the woocommerce_update_product_variation hook.
	 *
	 * @param int         $variation_id The variation ID.
	 * @param \WC_Product $variation The variation object.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_update_product_variation( $variation_id, $variation ): void {
		$variation_id = (int) $variation_id;
		$parent_id    = $variation instanceof \WC_Product ? $variation->get_parent_id() : null;
		$this->invalidate_variation_and_parent( $variation_id, $parent_id );
		$this->invalidate_variation_parent_cache( $variation_id );
	}

	/**
	 * Handle the woocommerce_new_product hook.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_new_product( $product_id ): void {
		$this->invalidate( (int) $product_id );
		$this->invalidate_products_list();
	}

	/**
	 * Handle the woocommerce_update_product hook.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_update_product( $product_id ): void {
		$this->invalidate( (int) $product_id );
	}

	/**
	 * Handle the woocommerce_before_delete_product hook.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_before_delete_product( $product_id ): void {
		$this->invalidate( (int) $product_id );
		$this->invalidate_products_list();
	}

	/**
	 * Handle the woocommerce_trash_product hook.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_trash_product( $product_id ): void {
		$this->invalidate( (int) $product_id );
		$this->invalidate_products_list();
	}

	/**
	 * Handle the woocommerce_before_delete_product_variation hook.
	 *
	 * @param int $variation_id The variation ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_before_delete_product_variation( $variation_id ): void {
		$variation_id = (int) $variation_id;
		$parent_id    = $this->get_variation_parent_id( $variation_id );
		$this->invalidate_variation_and_parent( $variation_id, $parent_id );
		$this->invalidate_variations_list( $parent_id );
		$this->invalidate_variation_parent_cache( $variation_id );
	}

	/**
	 * Handle the woocommerce_trash_product_variation hook.
	 *
	 * @param int $variation_id The variation ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_trash_product_variation( $variation_id ): void {
		$variation_id = (int) $variation_id;
		$parent_id    = $this->get_variation_parent_id( $variation_id );
		$this->invalidate_variation_and_parent( $variation_id, $parent_id );
		$this->invalidate_variations_list( $parent_id );
		$this->invalidate_variation_parent_cache( $variation_id );
	}

	/**
	 * Handle the woocommerce_updated_product_stock hook.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_updated_product_stock( $product_id ): void {
		$this->invalidate( (int) $product_id );
	}

	/**
	 * Handle the woocommerce_updated_product_price hook.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_updated_product_price( $product_id ): void {
		$this->invalidate( (int) $product_id );
	}

	/**
	 * Handle the woocommerce_updated_product_sales hook.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_updated_product_sales( $product_id ): void {
		$this->invalidate( (int) $product_id );
	}

	/**
	 * Handle the woocommerce_attribute_updated hook.
	 *
	 * @param int   $id The attribute ID.
	 * @param array $data The attribute data.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_attribute_updated( $id, $data ): void {
		if ( ! is_array( $data ) || ! isset( $data['attribute_name'] ) ) {
			return;
		}

		$taxonomy = wc_attribute_taxonomy_name( $data['attribute_name'] );
		$this->invalidate_products_with_attribute( $taxonomy );
	}

	/**
	 * Handle the woocommerce_attribute_deleted hook.
	 *
	 * @param int    $id The attribute ID.
	 * @param string $name The attribute name.
	 * @param string $taxonomy The attribute taxonomy.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_attribute_deleted( $id, $name, $taxonomy ): void {
		if ( ! is_string( $taxonomy ) || '' === $taxonomy ) {
			return;
		}

		$this->invalidate_products_with_attribute( $taxonomy );
	}

	/**
	 * Handle the woocommerce_updated_product_attribute_summary hook.
	 *
	 * @param int $variation_id The variation ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_woocommerce_updated_product_attribute_summary( $variation_id ): void {
		$this->invalidate_variation_and_parent( (int) $variation_id );
	}

	/**
	 * Handle the edited_term hook.
	 *
	 * @param int    $term_id The term ID.
	 * @param int    $tt_id The term taxonomy ID.
	 * @param string $taxonomy The taxonomy slug.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 *
	 * @internal
	 */
	public function handle_edited_term( $term_id, $tt_id, $taxonomy ): void {
		if ( ! is_string( $taxonomy ) ) {
			return;
		}

		// Only handle product attribute taxonomies.
		if ( 0 !== strpos( $taxonomy, 'pa_' ) ) {
			return;
		}

		$this->invalidate_products_with_term( (int) $tt_id );
	}

	/**
	 * Get the parent product ID for a variation.
	 *
	 * The result is cached in the object cache to avoid repeated lookups.
	 *
	 * @param int $variation_id The variation ID.
	 *
	 * @return int|null The parent product ID, or null if not found.
	 */
	private function get_variation_parent_id( int $variation_id ): ?int {
		$cache_key = "wc_variation_parent_{$variation_id}";
		$cached    = wp_cache_get( $cache_key, 'woocommerce' );

		if ( false !== $cached ) {
			return $cached ? $cached : null;
		}

		if ( $this->is_using_cpt_data_store() ) {
			$parent_id = wp_get_post_parent_id( $variation_id );
			$parent_id = $parent_id ? (int) $parent_id : null;
		} else {
			$variation = wc_get_product( $variation_id );
			$parent_id = $variation ? (int) $variation->get_parent_id() : null;
			$parent_id = $parent_id ? $parent_id : null;
		}

		// Cache the result (store 0 for null to distinguish from cache miss).
		wp_cache_set( $cache_key, $parent_id ?? 0, 'woocommerce', HOUR_IN_SECONDS );

		return $parent_id;
	}

	/**
	 * Invalidate the cached parent ID for a variation.
	 *
	 * @param int $variation_id The variation ID.
	 *
	 * @return void
	 */
	private function invalidate_variation_parent_cache( int $variation_id ): void {
		wp_cache_delete( "wc_variation_parent_{$variation_id}", 'woocommerce' );
	}

	/**
	 * Invalidate a variation and its parent product.
	 *
	 * @param int      $variation_id The variation ID.
	 * @param int|null $parent_id Optional parent product ID. If not provided, will be looked up.
	 *
	 * @return void
	 */
	private function invalidate_variation_and_parent( int $variation_id, ?int $parent_id = null ): void {
		$this->invalidate( $variation_id );

		if ( is_null( $parent_id ) ) {
			$parent_id = $this->get_variation_parent_id( $variation_id );
		}

		if ( ! $parent_id ) {
			return;
		}

		$this->invalidate( $parent_id );
	}

	/**
	 * Invalidate all products and variations that have a specific term assigned.
	 *
	 * Uses the indexed wp_term_relationships table for efficient lookups.
	 * The list of entities associated with the term is cached for performance;
	 * the TTL can be customized via the 'woocommerce_version_string_invalidator_taxonomy_lookup_ttl' filter.
	 *
	 * @param int $tt_id The term taxonomy ID.
	 *
	 * @return void
	 */
	private function invalidate_products_with_term( int $tt_id ): void {
		global $wpdb;

		$cache_key  = 'wc_cache_inv_term_' . $tt_id;
		$entity_ids = wp_cache_get( $cache_key, 'woocommerce' );

		if ( false === $entity_ids ) {
			$entity_ids = $wpdb->get_col(
				$wpdb->prepare(
					"SELECT tr.object_id
					FROM {$wpdb->term_relationships} tr
					INNER JOIN {$wpdb->posts} p ON tr.object_id = p.ID
					WHERE tr.term_taxonomy_id = %d
					AND p.post_type IN ('product', 'product_variation')",
					$tt_id
				)
			);

			/**
			 * Filters the cache TTL for queries that find entities associated with a term or taxonomy.
			 *
			 * These queries are used during cache invalidation to determine which entities
			 * (e.g., products, variations) need their cache cleared when a term or attribute changes.
			 *
			 * @since 10.5.0
			 *
			 * @param int    $ttl         Cache TTL in seconds. Default 300 (5 minutes).
			 * @param string $entity_type The type of entity being invalidated ('product').
			 */
			$ttl = apply_filters( 'woocommerce_version_string_invalidator_taxonomy_lookup_ttl', self::DEFAULT_TAXONOMY_LOOKUP_CACHE_TTL, 'product' );
			wp_cache_set( $cache_key, $entity_ids, 'woocommerce', $ttl );
		}

		foreach ( $entity_ids as $entity_id ) {
			$post_type = get_post_type( (int) $entity_id );
			if ( 'product_variation' === $post_type ) {
				$this->invalidate_variation_and_parent( (int) $entity_id );
			} else {
				$this->invalidate( (int) $entity_id );
			}
		}
	}

	/**
	 * Invalidate all products using a specific attribute taxonomy.
	 *
	 * The list of entities associated with the taxonomy is cached for performance;
	 * the TTL can be customized via the 'woocommerce_version_string_invalidator_taxonomy_lookup_ttl' filter.
	 *
	 * @param string $taxonomy The attribute taxonomy slug.
	 *
	 * @return void
	 */
	private function invalidate_products_with_attribute( string $taxonomy ): void {
		global $wpdb;

		$cache_key = 'wc_cache_inv_attr_' . $taxonomy;
		$cached    = wp_cache_get( $cache_key, 'woocommerce' );

		if ( false === $cached ) {
			$product_ids = $wpdb->get_col(
				$wpdb->prepare(
					"SELECT DISTINCT post_id FROM {$wpdb->postmeta}
					WHERE meta_key = '_product_attributes'
					AND meta_value LIKE %s",
					'%' . $wpdb->esc_like( 's:' . strlen( $taxonomy ) . ':"' . $taxonomy . '"' ) . '%'
				)
			);

			$variation_ids = $wpdb->get_col(
				$wpdb->prepare(
					"SELECT DISTINCT post_id FROM {$wpdb->postmeta}
					WHERE meta_key = %s",
					'attribute_' . $taxonomy
				)
			);

			$cached = array(
				'product_ids'   => $product_ids,
				'variation_ids' => $variation_ids,
			);

			// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment -- Documented above.
			$ttl = apply_filters( 'woocommerce_version_string_invalidator_taxonomy_lookup_ttl', self::DEFAULT_TAXONOMY_LOOKUP_CACHE_TTL, 'product' );
			wp_cache_set( $cache_key, $cached, 'woocommerce', $ttl );
		}

		foreach ( $cached['product_ids'] as $product_id ) {
			$this->invalidate( (int) $product_id );
		}

		foreach ( $cached['variation_ids'] as $variation_id ) {
			$this->invalidate_variation_and_parent( (int) $variation_id );
		}
	}

	/**
	 * Invalidate a product version string.
	 *
	 * @param int $product_id The product ID.
	 *
	 * @return void
	 *
	 * @since 10.5.0
	 */
	public function invalidate( int $product_id ): void {
		wc_get_container()->get( VersionStringGenerator::class )->delete_version( "product_{$product_id}" );
	}

	/**
	 * Invalidate the product list version string.
	 *
	 * This should be called when products are created, deleted, or change status,
	 * as these operations affect collection/list endpoints.
	 *
	 * @return void
	 */
	private function invalidate_products_list(): void {
		wc_get_container()->get( VersionStringGenerator::class )->delete_version( 'list_products' );
	}

	/**
	 * Invalidate the variations list version string for a specific product.
	 *
	 * This should be called when variations are created, deleted, or change status,
	 * as these operations affect the variations collection/list endpoint for the parent product.
	 *
	 * @param int|null $product_id The parent product ID, or null/0 to skip invalidation.
	 *
	 * @return void
	 */
	private function invalidate_variations_list( ?int $product_id ): void {
		if ( $product_id ) {
			wc_get_container()->get( VersionStringGenerator::class )->delete_version( "list_product_variations_{$product_id}" );
		}
	}
}

Directory Contents

Dirs: 0 × Files: 6
Name Size Perms Modified Actions
9.47 KB lrw-r--r-- 2026-07-28 11:37:13
Edit Download
3.75 KB lrw-r--r-- 2026-07-28 11:37:13
Edit Download
5.11 KB lrw-r--r-- 2026-07-28 11:37:13
Edit Download
20.41 KB lrw-r--r-- 2026-07-28 11:37:13
Edit Download
3.27 KB lrw-r--r-- 2026-07-28 11:37:13
Edit Download
5.51 KB lrw-r--r-- 2026-07-28 11:37:13
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI