Automattic\WooCommerce\Internal\Caches

ProductVersionStringInvalidator::handle_transition_post_statuspublicWC 10.6.0

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.

Method of the class: ProductVersionStringInvalidator{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ProductVersionStringInvalidator = new ProductVersionStringInvalidator();
$ProductVersionStringInvalidator->handle_transition_post_status( $new_status, $old_status, $post ): void;
$new_status(string) (required)
The new post status.
$old_status(string) (required)
The old post status.
$post(WP_Post) (required)
The post object.

Changelog

Since 10.6.0 Introduced.

ProductVersionStringInvalidator::handle_transition_post_status() code WC 10.8.1

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