我想在订单完整电子邮件中的产品中显示自定义ACF字段,我有这个钩子,它非常适合非变量产品:
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( $date = get_field('date', $product->get_id()) ) {
$item_name .= '<br /><strong>' . __( 'Date', 'woocommerce' ) . ': </strong>' . $date;
}
if( $location = get_field('location', $product->get_id()) ) {
$item_name .= '<br /><strong>' . __( 'Location', 'woocommerce' ) . ': </strong>' . $location;
}
return $item_name;
}
但是,虽然它对电子邮件中的简单产品显示我的自定义字段(日期和位置)很好,但对于可变产品却没有。
我似乎不明白为什么?
江户川乱折腾