Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCTransactionalEmailPostsManager::get_email_type_from_post_idpublicWC 1.0

Retrieves the WooCommerce email type from the options table when post ID is provided.

Method of the class: WCTransactionalEmailPostsManager{}

No Hooks.

Returns

String|null. The WooCommerce email type if found, null otherwise.

Usage

$WCTransactionalEmailPostsManager = new WCTransactionalEmailPostsManager();
$WCTransactionalEmailPostsManager->get_email_type_from_post_id( $post_id );
$post_id(int|string) (required)
The post ID.

WCTransactionalEmailPostsManager::get_email_type_from_post_id() code WC 10.3.6

public function get_email_type_from_post_id( $post_id ) {
	// Early return if post_id is invalid.
	if ( empty( $post_id ) ) {
		return null;
	}

	global $wpdb;

	$option_name = $wpdb->get_var(
		$wpdb->prepare(
			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s AND option_value = %s LIMIT 1",
			self::WC_OPTION_NAME,
			$post_id
		)
	);

	if ( empty( $option_name ) ) {
		return null;
	}

	return $this->get_email_type_from_option_name( $option_name );
}