Support

Account

Home Forums General Issues WooCommerce ACF field in email template

Solving

WooCommerce ACF field in email template

  • Hello, i want to make ACF field display in admin-new-email template.

    Hopping someone can help, i find this code, who displays my custom field in Cart page near price:

    
    function order_review_custom_field($product_price , $cart_item, $cart_item_key){
        $price= get_field('price_for', $cart_item['product_id']);
        return ($price) ?
            $product_price . '<div>/' . $price. '</div>'
            :
            $product_price . '<div> </div>';
    
    }
    add_filter('woocommerce_cart_item_price', 'order_review_custom_field', 999, 3);
    

    And its shows really good. But now i want display it in email template, but now not near price, but near quantity. So its like PRODUCT NAME next column Quantity/(my custom field) And when Sub total. I hope you know what i mean.

  • To display your custom field in the email template next to the quantity, you can modify the code to hook into the appropriate filter for the email template. Here’s an adjusted version of your code:
    `function email_custom_field($item_quantity, $cart_item, $cart_item_key, $order){
    $price = get_field(‘price_for’, $cart_item[‘product_id’]);
    return ($price) ?
    $item_quantity . ‘ / ‘ . $price
    :
    $item_quantity;
    }
    add_filter(‘woocommerce_order_item_quantity_html’, ’email_custom_field’, 999, 4);

    This code will display your custom field next to the quantity in DGCustomerFirst the email template. Ensure to place this code in your theme’s functions.php file or in a custom plugin.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.