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

Display product custom fields in cart next to each item name in Woocommerce

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

到目前为止我尝试的是我测试了 SOF () 和其他网站上列出的大约 10 个解决方案,但其中 none 似乎有效。

我知道如何显示这些数据,我只是不知道如何为产品标题下方的每个产品显示它。

我正在寻找能为我指明正确方向的人。

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

//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 );