2016-04-04 41 views
0

在Woocommerce中,我需要在完成的订单电子邮件上打印自定义字段。Woocommerce - 在电子邮件中打印产品的自定义字段

该模板在我的主题woocommerce/emails文件夹中完全独一无二,因为默认模板不适合我的需求。

因此我想显示如下: 名称,数量和两个自定义字段

这需要包含在客户完成-order.php电子邮件模板,但我不能肯定什么语法打印它是必要的。

我发现了一些谷歌搜索,但它不工作:

<?php foreach ($items as $item_id => $item) : 
$_product  = apply_filters('woocommerce_order_item_product', $order->get_product_from_item($item), $item); 
?> 

<p>Class: <?php echo get_post_meta($_product->id,'name',true); ?></p> 

<p>Date: <?php echo get_post_meta($_product->id,'date_text_field',true); ?></p> 

<p>Time: <?php echo get_post_meta($_product->id,'time_text_field',true); ?></p> 

<p>Number of Spaces: <?php echo get_post_meta($_product->id,'qty',true); ?></p> 


<?php endforeach; ?> 
+0

每个订单的类/日期/时间是否相同?还是它们是特定于特定订单的? – helgatheviking

回答

1

尝试增加以行动挂钩,
do_action('woocommerce_order_item_meta_start', $item_id, $item, $order);
OR
do_action('woocommerce_order_item_meta_end', $item_id, $item, $order);

这可以在下面的方式来使用:

add_action('woocommerce_order_item_name', 'action_custom_order_meta', 10, 3); 

OR

add_action('woocommerce_order_item_name', 'action_custon_order_meta', 10, 3); 

以下是回调处理函数。

function action_custom_order_meta($item_name, $item, $false){ 
    $product_id = $item['product_id']; 
    $product_custom_date = get_post_meta($product_id, 'product_custom_date', true); 
    $product_custom_time = get_post_meta($product_id, 'product_custom_time', true); 
    $product_custom_meta = 'Date: ' . $product_custom_date . ' <br> Time: ' . $product_custom_time; 
    echo $product_custom_meta; 
} 

将自定义字段名称更改为适当。您可能还需要根据自定义电子邮件所需的标记打包输出。

希望这会有所帮助。

相关问题