在 Woocommerce 交易电子邮件中显示产品 ACF 字段值
Display product ACF field value in Woocommerce transaction emails
是否可以在 Woocommerce 交易详细信息中的每个项目旁边有一个自定义字段(使用 ACF 创建)?
我有一个名为“shpng”的字段,其中包含发货日期,它每天从 syncsd 导入文件中更改,并最终出现在数据库中每个产品的 shpng 字段下。
尝试以下应该在电子邮件通知中的项目名称下显示您的 ACF 值的方法:
// Display Items Shipping ACF custom field value 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( is_wc_endpoint_url() )
return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
if( $shpng_value = get_field('shpng', $product->get_id()) ) {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping Date', 'woocommerce' ) . ': </strong>' . $shpng_value . '</p>';
}
return $item_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
续:
是否可以在 Woocommerce 交易详细信息中的每个项目旁边有一个自定义字段(使用 ACF 创建)?
我有一个名为“shpng”的字段,其中包含发货日期,它每天从 syncsd 导入文件中更改,并最终出现在数据库中每个产品的 shpng 字段下。
尝试以下应该在电子邮件通知中的项目名称下显示您的 ACF 值的方法:
// Display Items Shipping ACF custom field value 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( is_wc_endpoint_url() )
return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
if( $shpng_value = get_field('shpng', $product->get_id()) ) {
$item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
<strong>' . __( 'Shipping Date', 'woocommerce' ) . ': </strong>' . $shpng_value . '</p>';
}
return $item_name;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。
续: