Automattic\WooCommerce\Internal\EmailEditor
EmailApiController::save_email_data
Update WooCommerce specific option data by post name.
Method of the class: EmailApiController{}
No Hooks.
Returns
\WP_Error|null. Returns WP_Error if email validation fails, null otherwise.
Usage
$EmailApiController = new EmailApiController(); $EmailApiController->save_email_data( $data, $post ): ?\WP_Error;
- $data(array) (required)
- - Data that are stored in the wp_options table.
- $post(WP_Post) (required)
- - WP_Post object.
EmailApiController::save_email_data() EmailApiController::save email data code WC 10.3.6
public function save_email_data( array $data, \WP_Post $post ): ?\WP_Error {
$error = $this->validate_email_data( $data );
if ( is_wp_error( $error ) ) {
return new \WP_Error( 'invalid_email_data', implode( ' ', $error->get_error_messages() ), array( 'status' => 400 ) );
}
if ( ! array_key_exists( 'subject', $data ) && ! array_key_exists( 'preheader', $data ) ) {
return null;
}
$email_type = $this->post_manager->get_email_type_from_post_id( $post->ID );
$email = $this->get_email_by_type( $email_type ?? '' );
if ( ! $email ) {
return null; // not saving of type wc_email. Allow process to continue.
}
// Handle customer_refunded_order email type because it has two different subjects.
if ( 'customer_refunded_order' === $email_type ) {
if ( array_key_exists( 'subject_full', $data ) ) {
$email->update_option( 'subject_full', $data['subject_full'] );
}
if ( array_key_exists( 'subject_partial', $data ) ) {
$email->update_option( 'subject_partial', $data['subject_partial'] );
}
} elseif ( array_key_exists( 'subject', $data ) ) {
$email->update_option( 'subject', $data['subject'] );
}
if ( array_key_exists( 'preheader', $data ) ) {
$email->update_option( 'preheader', $data['preheader'] );
}
if ( array_key_exists( 'enabled', $data ) ) {
$email->update_option( 'enabled', $data['enabled'] ? 'yes' : 'no' );
}
if ( array_key_exists( 'recipient', $data ) ) {
$email->update_option( 'recipient', $data['recipient'] );
}
if ( array_key_exists( 'cc', $data ) ) {
$email->update_option( 'cc', $data['cc'] );
}
if ( array_key_exists( 'bcc', $data ) ) {
$email->update_option( 'bcc', $data['bcc'] );
}
return null;
}