Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 276
Wed Avatar asked Sep 05 '25 05:09

Wed


1 Answers

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 );
like image 162
Kashif Rafique Avatar answered Sep 07 '25 17:09

Kashif Rafique