所以我几乎明白了,但是指定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 )
to
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 )
但是它使电子邮件返回错误。
所以我几乎明白了,但是最后指定WooCommerce电子邮件的细节使我有些疑惑。我需要显示产品的ACF(高级自定义字段)字段(在这种情况下为...
通常这应该与下面的代码一起使用