Automattic\WooCommerce\Internal\Caches

CouponCodeLookupInvalidator::handle_transition_post_status │ public │ WC 11.2.0

Delete the lookup entry of a coupon that crosses the publish boundary.

Only transitions into or out of publish can change which ids a code resolves to, so other status changes (e.g. draft to pending) are ignored. wp_insert_post() reports new as the old status, so a brand-new published coupon takes this path too, which is what lets a newer coupon published under an already cached code win the lookup.

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

Хуков нет.

Возвращает

void. Ничего (null).

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

$CouponCodeLookupInvalidator = new CouponCodeLookupInvalidator();
$CouponCodeLookupInvalidator->handle_transition_post_status( $new_status, $old_status, $post ): void;
$new_status(строка) (обязательный)
New post status.
$old_status(строка) (обязательный)
Old post status.
$post(WP_Post) (обязательный)
Post object.

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

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

Код CouponCodeLookupInvalidator::handle_transition_post_status() WC 11.3.0

public function handle_transition_post_status( $new_status, $old_status, $post ): void {
	if ( ! $post instanceof \WP_Post || 'shop_coupon' !== $post->post_type || $new_status === $old_status ) {
		return;
	}

	if ( 'publish' === $old_status || 'publish' === $new_status ) {
		$this->invalidate( $post->post_title );
	}
}