duanbing2963 2016-09-30 13:03
浏览 35
已采纳

在woocommerce订单电子邮件中显示多个产品的自定义字段

I'm trying to display many custom fields created with ACF in the woocommerce email sent to the customer but I'm stuck on how handle the fields for a multiple product order.

So far I've achieved something with the code suggested by helgatheviking here but I'm able to display just CF from 1 product at once

Now I'm trying to figure out how to write it as a loop in order to display these fields for many products in the same mail. Unfortunately I'm a good copy&past guy, I'm still googling some way to correctly write a loop in this context but I had no luck so far. Can you help me?

here is the code in my functions.php so far:

<?php 
add_action( 'woocommerce_email_order_details', 'my_custom_order_details', 5, 4 );
function my_custom_order_details( $order, $sent_to_admin, $plain_text, $email ){

    if( $email->id == "customer_on_hold_order" ){

        $field1 = null;

        $items = $order->get_items();

        foreach ( $items as $item ) {
            $product_name = $item['name'];
            $product_id = $item['product_id'];
            $product_variation_id = $item['variation_id'];
            $field1 = get_post_meta($product_id, 'field-1', true);
            $field2 = get_post_meta($product_id, 'field-2', true);
            $field3 = get_post_meta($product_id, 'field-3', true);
            $field4 = get_post_meta($product_id, 'field-4', true);
        }

         if( $field1 && $plain_text ){

        echo "Field 1: " . $field1 . "

";

    } else if( $field1 && ! $plain_text ){ 

            <h2>My custom fields infos:</h2>
            <p><strong>Product Name:</strong> <?php echo $product_name ?></p>
            <p><strong>Field 1:</strong> <?php echo $field1 ?></p>
            <p><strong>Field 2:</strong> <?php echo $field2 ?></p>
            <p><strong>Field 3:</strong> <?php echo $field3 ?></p>
            <p><strong>Field 4:</strong> <?php echo $field4 ?></p>

<?php
        }

    }
}
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号
      • ¥15 利用kmeans或kshape聚类分析对归一化的无量纲时间-降雨序列进行聚类
      • ¥15 protel99.SE提示一下弹窗
      • ¥15 银河麒麟v10 执行.run失败如何解决