我想根据产品ID和附件ID将附件添加到Woocommerce中的“新订单”电子邮件中。
我试图将此代码添加到Woocommerce的“ Woocommerce电子邮件附件”插件的woocommerce-email-attachments.php中。
add_filter( 'woocommerce_email_attachments', 'add_woocommerce_attachments_for_certain_product', 10, 3 );
function add_woocommerce_attachments_for_certain_product ( $attachments, $email_id, $email_order ){
$product_id = array( 2707, 2708, 2709, 2710, 2711, 2712, 2713, 2714, 2715, 2716, 2717, 2718 );
$attachment_id = 9347;
if( $email_id === 'new_order' ){
$order = wc_get_order( $email_order );
$items = $order->get_items();
foreach ( $items as $item ) {
if ( in_array( $item->get_product_id(), $product_id ) ) {
$attachments[] = get_attached_file( $attachment_id );
}
}
}
return $attachments;
}
add_filter( 'woocommerce_email_attachments', 'add_woocommerce_attachments_for_certain_product', 10, 3 );
function add_woocommerce_attachments_for_certain_product ( $attachments, $email_id, $email_order ){
$product_id = array( 2719, 2720, 2721, 2722, 2723, 2724, 2725, 2726, 2727, 2728, 2729, 2730 );
$attachment_id = 9351;
if( $email_id === 'new_order' ){
$order = wc_get_order( $email_order );
$items = $order->get_items();
foreach ( $items as $item ) {
if ( in_array( $item->get_product_id(), $product_id ) ) {
$attachments[] = get_attached_file( $attachment_id );
}
}
}
return $attachments;
}
但是当我上传文件时,它给出了致命错误。我究竟做错了什么? :-)