是否可以在Woocommerce交易明细中的每个项目旁边添加使用ACF创建的自定义字段?
我有一个名为“shpng”的字段,其中包含运输日期,它每天从同步导入文件更改,并最终出现在每个产品的shpng字段下的数据库中。
是否可以在Woocommerce交易明细中的每个项目旁边添加使用ACF创建的自定义字段?
我有一个名为“shpng”的字段,其中包含运输日期,它每天从同步导入文件更改,并最终出现在每个产品的shpng字段下的数据库中。
// 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文件中。经过测试,可以正常工作。