在Woocommerce中每个商品名称旁边的购物车中显示产品自定义字段 [英] Display product custom fields in cart next to each item name in Woocommerce

查看:164
本文介绍了在Woocommerce中每个商品名称旁边的购物车中显示产品自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一家商店中,每种产品的交货日期都不同。我使用ACF将这个日期存储在名为 shpng 的自定义字段中。我想要达到的目的是在购物车中每个产品旁边显示适当的字段。

I have a store where each product has different delivery date. I have this date stored in a custom field called shpng using ACF. What I'm trying to achieve is to display appropriate field next to each product in cart.

到目前为止,我已经测试了SOF上列出的大约10种解决方案( 示例),但在其他站点上似乎都不起作用。

What I tried so far is that I tested approximately 10 solutions listed on SOF (example) and on the other sites, but none of them seems to work.

我知道如何显示此数据,我只是不知道如何显示

I know how to display this data, I just don't know how to display it for each product below product title.

我正在寻找可以向我指出正确方向的人。

I'm looking for someone to point me in the right direction.

推荐答案

您可以使用 woocommerce_after_cart_item_name 钩子,用于在产品标题下方显示每个产品的ACF自定义字段的值。

You can use woocommerce_after_cart_item_name hook for displaying the value of ACF custom field for each product below the product title.

//To display the ACF custom field 'shpng' below the product title on cart page
function lh_cart_item_sub_title( $cart_item ) {
    $shpng = get_field( 'shpng', $cart_item['product_id'] );
    echo "<div class='small custom-cart-shipping-date'>My Custom Shipping Date: $shpng.</div>";
}
add_action( 'woocommerce_after_cart_item_name', 'lh_cart_item_sub_title', 10, 1 );

这篇关于在Woocommerce中每个商品名称旁边的购物车中显示产品自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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