Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailPostsCleanup::was_never_customized │ private static │ WC 1.0

Decide whether a stored email post was never customized by a merchant.

True when any of the following independent signals holds:

  • the content matches the canonical core render recomputed right now;
  • the content still matches the sync source hash stamped at creation or backfill time (untouched even though core moved on — deleting is equivalent to what the auto-applier would do, just cheaper);
  • no valid source hash exists (email not covered by the sync registry) and the GMT creation/modification timestamps show no edit ever happened.

The stored _wc_email_template_status meta is deliberately not trusted on its own — it can be stale (sweeps only run after upgrades) or absent.

Method of the class: WCEmailPostsCleanup{}

No Hooks.

Returns

bool. True when the post can safely fall back to the file template.

Usage

$result = WCEmailPostsCleanup::was_never_customized( $post, $email ): bool;
$post(WP_Post) (required)
The stored email post.
$email(WC_Email) (required)
The registered email instance.

WCEmailPostsCleanup::was_never_customized() code WC 11.1.2

private static function was_never_customized( \WP_Post $post, \WC_Email $email ): bool {
	$post_hash = sha1( (string) $post->post_content );

	$canonical_hash = sha1( WCTransactionalEmailPostsGenerator::compute_canonical_post_content( $email ) );
	if ( $post_hash === $canonical_hash ) {
		return true;
	}

	$stored_hash = get_post_meta( $post->ID, WCEmailTemplateDivergenceDetector::SOURCE_HASH_META_KEY, true );
	if ( is_string( $stored_hash ) && 1 === preg_match( '/^[0-9a-f]{40}$/', $stored_hash ) ) {
		return $post_hash === $stored_hash;
	}

	// GMT columns only: the local pair is computed with the site offset at
	// write time, so a timezone change between creation and an edit can
	// make it match coincidentally — and any extra signal here widens a
	// hard-delete decision.
	return $post->post_date_gmt === $post->post_modified_gmt;
}