我一直在寻找解决方案,因为我的woocommerce问题。我有能力让客户添加他自己的电子邮件和他朋友的电子邮件。但问题是,woocommerce只会向自己的电子邮件发送电子邮件。我已经使用一个名为:Woo Checkout Field Editor Pro的插件添加了朋友输入的电子邮件字段
我的问题是:如何添加此自定义输入以包含在订单完成后发送的电子邮件中。
我发现以下代码可能有用,但我不擅长用PHP编程,所以我不熟悉如何解决这个问题。
// Checks subscription for additional emails
add_filter( 'woocommerce_email_recipient_customer_completed_renewal_order', 'woocommerce_email_customer_invoice_add_recipients', 10, 2 );
add_filter( 'woocommerce_email_recipient_customer_renewal_invoice', 'woocommerce_email_customer_invoice_add_recipients', 10, 2 );
function woocommerce_email_customer_invoice_add_recipients( $recipient, $order ) {
// Finds subscription for the order
$subscription = wcs_get_subscriptions_for_order( $order, array( 'order_type' => array( 'parent', 'renewal' ) ) );
if ( $subscription and array_values($subscription)[0] ) {
// Find first subscription ID
$subscription_id = array_values($subscription)[0]->id;
// Check ACF field for additional emails
$additional_emails = get_field('additional_emails', $subscription_id);
if ($additional_emails) {
// Found additional emails so add them to the $recipients list
$recipient .= ', ' . $additional_emails;
}
}
return $recipient;
}
以下代码:
add_filter( 'woocommerce_email_recipient_customer_invoice', 'woocommerce_email_customer_invoice_add_recipients' );
function woocommerce_email_customer_invoice_add_recipients( $recipient, $order ) {
if ( 'joe@acme.com' == $recipient ) {
$recipient .= ', billing@acme.com';
}
return $recipient;
}