在 Woocommerce 交易电子邮件中显示产品 ACF 字段值 [英] Display product ACF field value in Woocommerce transaction emails

查看:39
本文介绍了在 Woocommerce 交易电子邮件中显示产品 ACF 字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Woocommerce 交易详细信息中的每个项目旁边都有一个自定义字段(使用 ACF 创建)?

Is it possible to have a custom field (created using ACF) next to each item in Woocommerce transaction details?

我有一个名为shpng"的字段,其中包含发货日期,它每天从 syncsd 导入文件更改,并最终在每个产品的 shpng 字段下的数据库中.

I have a field called ‘shpng’ which contains the shipping date, and it is changed daily from syncsd import file and ends up in the database under the shpng field of each product.

推荐答案

请尝试以下操作,以便在电子邮件通知中的项目名称下显示您的 ACF 值:

Try the following that should display your ACF value under the item name in email notifications:

// 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 文件中.经测试有效.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

继续: 在 Woocommerce 中每个项目名称旁边的购物车中显示产品自定义字段

这篇关于在 Woocommerce 交易电子邮件中显示产品 ACF 字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆