Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCTransactionalEmailPostsGenerator::build_filtered_post_datapublic staticWC 10.8.0

Build the wp_insert_post() for a given email and apply the woocommerce_email_content_post_data

Extracted so the generator and the divergence detector observe the exact same pre-insert post payload, guaranteeing by construction that the hash stamped in {@see self::generate_single_template()} and the hash recomputed in WCEmailTemplateDivergenceDetector hash identical input.

Method of the class: WCTransactionalEmailPostsGenerator{}

Hooks from the method

Returns

Array. The post data array after the woocommerce_email_content_post_data runs.

Usage

$result = WCTransactionalEmailPostsGenerator::build_filtered_post_data( $email_type, $email ): array;
$email_type(string) (required)
The email type identifier (e.g. customer_processing_order).
$email(WC_Email) (required)
The transactional email instance.

Changelog

Since 10.8.0 Introduced.

WCTransactionalEmailPostsGenerator::build_filtered_post_data() code WC 10.8.1

public static function build_filtered_post_data( string $email_type, $email ): array {
	$post_data = array(
		'post_type'    => Integration::EMAIL_POST_TYPE,
		'post_status'  => 'publish',
		'post_name'    => $email_type,
		'post_title'   => $email->get_title(),
		'post_excerpt' => $email->get_description(),
		'post_content' => self::render_block_template_html( $email ),
		'meta_input'   => array(
			'_wp_page_template' => ( new WooEmailTemplate() )->get_slug(),
		),
	);

	/**
	 * Filter the email content post data before creating the post.
	 *
	 * Allows third-party integrators to modify the post data (title, content, meta, etc.)
	 * before the email content post is created.
	 *
	 * @since 10.5.0
	 * @param array     $post_data  The post data array to be used for wp_insert_post().
	 * @param string    $email_type The email type identifier (e.g., 'customer_processing_order').
	 * @param \WC_Email $email      The WooCommerce email object.
	 */
	$filtered_post_data = apply_filters( 'woocommerce_email_content_post_data', $post_data, $email_type, $email );

	return is_array( $filtered_post_data ) ? $filtered_post_data : $post_data;
}