gpt4 book ai didi

woocommerce - 在新订单电子邮件中显示自定义产品字段

转载 作者:行者123 更新时间:2023-12-01 23:22:28 27 4
gpt4 key购买 nike

我在名为类(class)日期 的产品中创建了一个自定义字段。我给它设定了一个日期,例如 1 月 30 日。这就是我在电子邮件中收到的内容,但没有任何显示……我是不是遗漏了什么?使用下面的新代码段编辑的代码

enter image description here

    <?php
/**
* Customer processing order email
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.4.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

?>

<?php
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
$course_date=get_post_meta($product_id, 'course-date', true);
//Note $course_date will get overwritten if there are more than one items in the order.
}
?>

<?php do_action('woocommerce_email_header', $email_heading); ?>

<p>This email is to notify you of your recent registration for the <b>Level 1 - Think and Grow Rich Institute Course</b>!</p>

<p>You are registered to attend on:</p>

<p><?php printf( __( '<b>Registration ID:</b> %s', 'woocommerce' ), $order->get_order_number() ); ?></p>
<p><b>Course Registration Date:</b> <?php echo get_post_meta($post->id, 'course-date', true); ?></p>
<p><b>Time:</b> 8am Registration - 9am Event Begins (<a href="http://allfansnomoney.com/thinkandgrowrich/tentative-schedule/" target="_blank">See Full Schedule</a>)</p>
<p><b>Location:</b> 240 Belfield Rd, Toronto, ON M9W 1H3</p>

<p>If you have any questions please contact us by e-mail: <a href="mailto:contact@thinkandgrowrichinstitute.com">contact@thinkandgrowrichinstitute.com</a>.</p>

<p>Sincerely,<BR/>
The Think and Grow Rich Institute Team</p><BR/>

<p><em><b>"Whatever The Mind Can Conceive and Believe, It Will Achieve."</b> - Napoleon Hill</em></p>

<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>

<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text ); ?>

<?php do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text ); ?>

<?php do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text ); ?>

<?php do_action( 'woocommerce_email_footer' ); ?>

最佳答案

希望您能从这个答案中学到更多,它会增加您对 WooCommerce 的了解。

对于您发送的“客户处理订单电子邮件”的片段。

系统无法在此处找到 $_product->id 的值。所以它不起作用。

您必须通过在初始测试电子邮件中打印产品 ID 本身来调试它。

如果您无法获取产品 ID。这里有更多信息。

一个订单可能有多个产品。因此,使用元字段查找产品可能会很麻烦,尤其是当您对应该显示哪个产品的元字段有疑问时。

简单的方法是使用给定的对象 $order 从该对象中检索订单 ID,然后找到与该订单关联的所有产品,然后找到这些产品的元字段值。

<?php
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
$course_date=get_post_meta($product_id, 'course-date', true);
if(isset($course_date) && $course_date!=""){
echo "<p><b>Course Registration Date:</b>".$course_date."</p>";
}
}
?>

让我们知道这是否让您对问题有任何了解。

关于woocommerce - 在新订单电子邮件中显示自定义产品字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34845026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com