Письма WooCommerce для новых заказов, как изменить программно?Php

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Письма WooCommerce для новых заказов, как изменить программно?

Сообщение Anonymous »


when you go to WooCommerce->Settings->Emails you can set which email address you want for new orders, failed orders, cancelled orders and so on.

I'm trying to see how I can change all of them programmatically, so I created a little template with an input field and a submit button to change these emails all at once, but the only email address that changes is the one for Email Sender Options (the setting at the bottom of the WooCommerce->Settings->Emails page), and not the ones for new order, cancelled order and failed orders.

Inspecting the possible hooks, I thought the following code should do the trick:

function change_notification_email_callback() { // Log form data for debugging error_log( print_r( $_POST, true ) ); if ( isset( $_POST['new_notification_email'] ) && ! empty( $_POST['new_notification_email'] ) ) { $new_email = sanitize_email( $_POST['new_notification_email'] ); // Log current value of woocommerce_new_order_recipient option $old_recipient_email = get_option( 'woocommerce_new_order_recipient' ); error_log( 'Old Recipient Email: ' . $old_recipient_email ); // Update the notification email update_option( 'woocommerce_email_from_address', $new_email ); update_option( 'woocommerce_new_order_email', $new_email ); update_option( 'woocommerce_cancelled_order_email', $new_email ); update_option( 'woocommerce_failed_order_email', $new_email ); // Log updated value of woocommerce_new_order_recipient option $updated_recipient_email = get_option( 'woocommerce_new_order_recipient' ); error_log( 'Updated Recipient Email: ' . $updated_recipient_email ); // Log updated value of woocommerce_cancelled_order_recipient option $updated_recipient_email_cancelled = get_option( 'woocommerce_cancelled_order_recipient' ); error_log( 'Updated Recipient Email for cancelled: ' . $updated_recipient_email_cancelled ); // Set success message $message = 'Notification email changed successfully.'; $notice_type = 'success'; } else { // Set error message $message = 'Failed to change notification email. Please enter a valid email.'; $notice_type = 'error'; } // Set admin notice add_flash_notice( $message, $notice_type ); // Redirect back to the WooCommerce dashboard page after email change wp_redirect( admin_url( 'admin.php?page=wc-dashboard' ) ); exit; } So again, under the // Update the notification emails, only the first update_option works, and even though the logs show that all instances were changed (woocommerce_email_from_address, woocommerce_new_order_email, etc) and even looking up those fields in the wp_options table they show updated, but when I check the WooCommerce->Settings->Emails page, those are still unchanged (image below shows what I mean). I did a test to put a order through to make sure it wasn't cache or something, but it's going to whatever email is there. Does anyone know what else I can try?


Изображение



Источник: https://stackoverflow.com/questions/780 ... mmatically
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»