【发布时间】:2019-02-17 23:12:33
【问题描述】:
Woocommerce 交易详情中的每个项目旁边是否可以有一个自定义字段(使用 ACF 创建)?
我有一个名为“shpng”的字段,其中包含发货日期,并且每天都会从 syncsd 导入文件中更改,并最终在每个产品的 shpng 字段下的数据库中。
【问题讨论】:
标签: php wordpress woocommerce advanced-custom-fields email-notifications
Woocommerce 交易详情中的每个项目旁边是否可以有一个自定义字段(使用 ACF 创建)?
我有一个名为“shpng”的字段,其中包含发货日期,并且每天都会从 syncsd 导入文件中更改,并最终在每个产品的 shpng 字段下的数据库中。
【问题讨论】:
标签: php wordpress woocommerce advanced-custom-fields email-notifications
尝试以下操作,以在电子邮件通知中的项目名称下显示您的 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 文件中。经过测试并且可以工作。
继续: Display product custom fields in cart next to each item name in Woocommerce
【讨论】: