Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display product ACF field value in Woocommerce transaction emails

Is it possible to have a custom field (created using ACF) next to each item in Woocommerce transaction details?

I have a field called ‘shpng’ which contains the shipping date, and it is changed daily from syncsd import file and ends up in the database under the shpng field of each product.

like image 571
Wed Avatar asked Dec 01 '25 05:12

Wed


1 Answers

Try the following that should display your ACF value under the item name in email notifications:

// Display Items Shipping ACF custom field value in email notification
add_filter( 'woocommerce_order_item_name', 'custom_order_item_name', 10, 2 );
function custom_order_item_name( $item_name, $item ) {
    // Targeting email notifications only
    if( is_wc_endpoint_url() ) 
        return $item_name;

    // Get the WC_Product object (from order item)
    $product = $item->get_product();

    if( $shpng_value = get_field('shpng', $product->get_id()) ) {
        $item_name .= '<br><p class="item-shpng" style="margin:12px 0 0;">
        <strong>' . __( 'Shipping Date', 'woocommerce' ) . ': </strong>' . $shpng_value . '</p>';
    }
    return $item_name;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

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

like image 110
LoicTheAztec Avatar answered Dec 03 '25 21:12

LoicTheAztec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!