我有一家商店,每种产品都有不同的交货日期。我将此日期存储在名为的自定义字段中shpng
使用ACF。我想要实现的是在购物车中的每个产品旁边显示适当的字段。
到目前为止我尝试过的是,我测试了 SOF 上列出的大约 10 个解决方案(example https://stackoverflow.com/questions/39400033/adding-a-notice-on-cart-and-checkout-page-based-on-item-custom-field-highest-val)以及其他网站,但它们似乎都不起作用。
我知道如何显示这些数据,只是不知道如何为产品标题下方的每个产品显示它。
我正在寻找有人为我指明正确的方向。
您可以使用woocommerce_after_cart_item_name https://github.com/woocommerce/woocommerce/blob/master/templates/cart/cart.php#L82用于在产品标题下方显示每个产品的 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 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)