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

无人久伴 提交于 2019-12-11 05:26:33

问题


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.

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.


回答1:


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


来源:https://stackoverflow.com/questions/54673702/display-product-custom-fields-in-cart-next-to-each-item-name-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!