Я использую WP 4.9.9 + WC 3.5.1.
Я пытаюсь прикрепить файл изображения к электронной почте.Это электронное письмо, отправленное после созданного заказа.В указанном порядке поле с именем ac_order_customer_image (создано с помощью плагина ACF).
В моем файле function.php присутствует такой код:
add_filter( 'woocommerce_email_attachments', 'woocommerce_emails_attach_ac_order_customer_image', 10, 3);
function woocommerce_emails_attach_ac_order_customer_image($attachments, $status, $order) {
error_log('woocommerce_emails_attach_ac_order_customer_image START');
if ( ! is_object( $order ) || ! isset( $status ) ) {
return $attachments;
}
error_log('woocommerce_emails_attach_ac_order_customer_image ORDER and STATUS setted');
if ( empty( $order ) ) {
return $attachments;
}
error_log('woocommerce_emails_attach_ac_order_customer_image ORDER not empty');
$image = get_field('ac_order_customer_image', $order->ID);
error_log('woocommerce_emails_attach_ac_order_customer_image IMAGE: ' . serialize($image));
if ( ! $image ) {
return $attachments;
}
error_log('woocommerce_emails_attach_ac_order_customer_image IMAGE is setted ');
if (is_array($image)){
error_log('woocommerce_emails_attach_ac_order_customer_image IMAGE is ARRAY. Add URL from ARRAY ');
$attachments[] = $image['url'];
}
if (is_int($image)){
error_log('woocommerce_emails_attach_ac_order_customer_image IMAGE is INT. Get URL and ADD ');
$url = wp_get_attachment_image_src($image);
if (is_array($url)){
error_log('woocommerce_emails_attach_ac_order_customer_image IMAGE(ret arr): ' . serialize($url[0]));
$attachments[] = $url[0];
}
if (is_string($url)){
error_log('woocommerce_emails_attach_ac_order_customer_image IMAGE: ' . $url);
$attachments[] = $url;
}
}
if (is_string($image)){
error_log('woocommerce_emails_attach_ac_order_customer_image IMAGE is STRING. Add URL string ');
$attachments[] = $image;
}
error_log('woocommerce_emails_attach_ac_order_customer_image FINISH ');
return $attachments;
}
Я получаю письмо, но без вложений.Что я делаю не так?
PS: error_log:
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image START, referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image ORDER and STATUS setted, referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image ORDER not empty, referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: ID was called incorrectly. Order properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), do_action('template_redirect'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::do_wc_ajax, do_action('wc_ajax_checkout'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_AJAX::checkout, WC_Checkout->process_checkout, WC_Checkout->process_order_payment, WC_Gateway_BACS->process_payment, WC_Order->update_status, WC_Order->save, WC_Order->status_transition, do_action('woocommerce_order_status_pending_to_on-hold'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_Emails::send_transactional_email, do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, WC_Email_Customer_On_Hold_Order->trigger, WC_Email->get_attachments, apply_filters('woocommerce_email_attachments'), WP_Hook->apply_filters, call_user_func_array, woocommerce_emails_attach_ac_order_customer_image, WC_Abstract_Legacy_Order->__get, wc_doing_it_wrong. This message was added in version 3.0., referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image IMAGE: i:511;, referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image IMAGE is setted , referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image IMAGE is INT. Get URL and ADD , referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image IMAGE(ret arr): s:134:"http://example.com/wp-content/uploads/2019/01/24774eede17915054f42f2dbd16bee28_client_upload_file_2019_01_03_17_01_05-1-150x150.jpeg";, referer: http://example.com/checkout/
[Thu Jan 03 20:27:08 2019] [warn] [client 95.31.12.33] mod_fcgid: stderr: woocommerce_emails_attach_ac_order_customer_image FINISH , referer: http://example.com/checkout/