【发布时间】:2020-09-01 17:32:42
【问题描述】:
所以我几乎明白了,但是指定 WooCommerce 电子邮件的最后一个细节在这里让我有点困惑。
我需要显示产品的 ACF(高级自定义字段)字段(在这种情况下是自定义发货时间)
- 但仅在新订单电子邮件中(处理订单和等待付款订单发送给客户),然后将新订单电子邮件发送给管理员。
这是我找到的主要方式:"Display product ACF field value in Woocommerce transaction emails"提前谢谢@LoicTheAztec
我还添加了一些条件设置(请注意我的 PHP 刚开始复制粘贴) 效果很好。
但是,我无法解决的是让它仅适用于新订单电子邮件。 我有这样的设置,它可以工作,但是它显示在所有包含电子邮件订单详细信息的电子邮件上,并且我无法在已完成的订单电子邮件上显示运输时间,因为它会造成混乱。
// Display product ACF custom field value shipping in email notification
add_filter( 'woocommerce_order_item_name', 'custom_order_item_name', 10, 2 );
function custom_order_item_name( $item_name, $item ) {
// Targeting email notifications only
if ( 'new_order' == $email->id )
return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
$othershipping = get_field( 'shipping_custom', $product->get_id());
if( $shpng_value = get_field('shipping_', $product->get_id())== "24h") {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping time', 'woocommerce' ) . ': </strong>' . '<p>Get it tomorrow(24h)</p>' . '</p>';
}
elseif( $shpng_value = get_field('shipping_', $product->get_id())== "2-5 days") {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping time', 'woocommerce' ) . ': </strong>' . '<p>2-5 days</p>' . '</p>';
}
elseif( $shpng_value = get_field('shipping_', $product->get_id())== "other") {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping time', 'woocommerce' ) . ': </strong>' . $othershipping . '</p>';
}
return $item_name;
}
我已经尝试过切换
if ( 'new_order' == $email->id )
到
if ( 'new_order' != $email->id )
但这只是让它无法在任何地方工作。
我也觉得可能是这个部分
function custom_order_item_name( $item_name, $item ) {
我需要在哪里添加($order, $sent_to_admin, $plain_text, $email )
function custom_order_item_name( $item_name, $item, $order, $sent_to_admin, $plain_text, $email )
但这会使电子邮件返回错误。
【问题讨论】:
标签: php wordpress woocommerce advanced-custom-fields hook-woocommerce