Automattic\WooCommerce\Internal\Admin

CustomerEffortScoreTracks::maybe_clear_ces_tracks_queue()publicWC 1.0

Maybe clear the CES tracks queue, executed on every page load. If the clear option is set it clears the queue. In practice, this executes a page load after the queued CES tracks are displayed on the client, which sets the clear option.

Method of the class: CustomerEffortScoreTracks{}

No Hooks.

Return

null. Nothing.

Usage

$CustomerEffortScoreTracks = new CustomerEffortScoreTracks();
$CustomerEffortScoreTracks->maybe_clear_ces_tracks_queue();

CustomerEffortScoreTracks::maybe_clear_ces_tracks_queue() code WC 7.1.0

public function maybe_clear_ces_tracks_queue() {
	$clear_ces_tracks_queue_for_page = get_option(
		self::CLEAR_CES_TRACKS_QUEUE_FOR_PAGE_OPTION_NAME,
		false
	);

	if ( ! $clear_ces_tracks_queue_for_page ) {
		return;
	}

	$queue           = get_option(
		self::CES_TRACKS_QUEUE_OPTION_NAME,
		array()
	);
	$remaining_items = array_filter(
		$queue,
		function ( $item ) use ( $clear_ces_tracks_queue_for_page ) {
			return $clear_ces_tracks_queue_for_page['pagenow'] !== $item['pagenow']
			|| $clear_ces_tracks_queue_for_page['adminpage'] !== $item['adminpage'];
		}
	);

	update_option(
		self::CES_TRACKS_QUEUE_OPTION_NAME,
		array_values( $remaining_items )
	);
	update_option( self::CLEAR_CES_TRACKS_QUEUE_FOR_PAGE_OPTION_NAME, false );
}