在 WooCommerce 第 3 方插件电子邮件模板上显示一些订单详细信息

问题描述 投票:0回答:1

我继承了一个 PDF 凭证插件,希望在 woocommerce 电子邮件模板中获取并显示自定义订单数据。这是原始电子邮件代码。 我想显示客户账单的名字。

<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<p><?php printf( _n( "Hi there. You've been sent a voucher!", "Hi there. You've been sent %d vouchers!", $voucher_count, 'woocommerce-pdf-product-vouchers' ), $voucher_count ); ?></p>

<?php do_action( 'woocommerce_email_footer', $email ); ?>

查看开发者文档,我们应该能够使用 $voucher->get_order() 查询订单对象。我已经尝试过该方法和以下方法,但它没有返回任何结果。

$order    = wc_get_order( $order_id );
$first_name = $order->get_billing_first_name();
echo $first_name;

我尝试过:

<?php do_action( 'woocommerce_email_header', $email_heading, $email ); 
  $order = $email->object;
  $first_name = $order->get_billing_first_name; 
    echo $first_name;    
?>

我错过了什么?

php wordpress templates woocommerce orders
1个回答
0
投票

在 WooCommerce PDF Product Vouchers 插件

voucher-recipient.php
模板文件中,您可以看到:

/**
 * Voucher recipient html email
 *
 * @type \WC_Order $order the order object associated with this email
 * @type string $email_heading the configurable email heading
 * @type int $voucher_count the number of vouchers being attached
 * @type string $message optional customer-supplied message to display
 * @type string $recipient_name optional customer-supplied recipient name
 * @type \WC_PDF_Product_Vouchers_Email_Voucher_Recipient $email the email being sent
 *
 * @version 3.5.3
 * @since 1.2
 */

这意味着 WC_Order 对象

$order
已在此模板中可用。

首先,将此模板文件复制到您的子主题中的“woocommerce”文件夹>“emails”子文件夹中,以便能够覆盖它。

enter image description here

完成后,打开编辑复制的文件,并替换行:

<p><?php printf( _n( "Hi there. You've been sent a voucher!", "Hi there. You've been sent %d vouchers!", $voucher_count, 'woocommerce-pdf-product-vouchers' ), $voucher_count ); ?></p>

与:

<p><?php printf( __("Hi %s. ", 'woocommerce-pdf-product-vouchers'), $order->get_billing_first_name() ) . printf( _n( "You've been sent a voucher!", "You've been sent %d vouchers!", $voucher_count, 'woocommerce-pdf-product-vouchers' ), $voucher_count ); ?></p>

保存。现在应该显示客户的名字。

© www.soinside.com 2019 - 2024. All rights reserved.