Automattic\WooCommerce\Admin\Features

LaunchYourStore::maybe_track_template_change()publicWC 1.0

Track when coming soon template is changed.

Method of the class: LaunchYourStore{}

No Hooks.

Return

null. Nothing (null).

Usage

$LaunchYourStore = new LaunchYourStore();
$LaunchYourStore->maybe_track_template_change( $post_id, $post, $update );
$post_id(int) (required)
The post ID.
$post(WP_Post) (required)
The post object.
$update(true|false) (required)
Whether the post is being updated.

LaunchYourStore::maybe_track_template_change() code WC 9.7.1

public function maybe_track_template_change( $post_id, $post, $update ) {
	if ( ! $post instanceof \WP_Post || ! isset( $post->post_name, $post->post_title ) ) {
		return;
	}

	// Check multiple fields to avoid false matches with non-WooCommerce templates.
	if ( 'coming-soon' === $post->post_name && 'Page: Coming soon' === $post->post_title ) {
		$matches = array();
		$content = $post->post_content;
		preg_match( '/"comingSoonPatternId":"([^"]+)"/', $content, $matches );

		if ( isset( $matches[1] ) ) {
			wc_admin_record_tracks_event(
				'coming_soon_template_saved',
				array(
					'pattern_id' => $matches[1],
					'is_update'  => $update,
				)
			);
		}
	}
}