Search code examples
phpwordpresswoocommerceadvanced-custom-fieldscart

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.


Solution

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