首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WooCommerce电子邮件中添加自定义字段变量

在WooCommerce电子邮件中添加自定义字段变量
EN

Stack Overflow用户
提问于 2017-06-15 12:38:09
回答 2查看 1.5K关注 0票数 0

我为我的WooCommerce用户提供了一些自定义变量,如:

代码语言:javascript
复制
billing_pin
billing_piva

等等。

当一个新客户被创建,它会收到一个新帐户的电子邮件,我已经修改了它。

现在我的电子邮件是:

代码语言:javascript
复制
<?php
/**
 * Customer new account email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-new-account.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates/Emails
 * @version     1.6.4
 */

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

?>

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

    <p><?php printf( __( 'Il tuo account di Magazzino Perfetto è stato creato con successo. Da questo momento potrai iniziare ad usare tutti i nostri servizi per aumentare la produttività della tua azienda. <b>Il tuo nome utente è la tua email</b>')); ?></p>

<?php if ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) && $password_generated ) : ?>

    <p><?php printf( __( 'La tua password è stata generata automaticamente. La trovi di seguito: %s', 'woocommerce' ), '<strong>' . esc_html( $user_pass ) . '</strong>' ); ?></p>

<?php endif; ?>

    <p><?php printf( __( 'Per accedere al riepilogo ordine, fare upgrade, modificare la password, visualizzare la licenza e scaricare le fatture, puoi cliccare sul seguente link: %s.', 'woocommerce' ), make_clickable( esc_url( wc_get_page_permalink( 'myaccount' ) ) ) ); ?></p>

    <p><?php printf( __( 'Per iniziare subito a lavorare puoi accedere al <b>pannello di controllo</b> online all\'indirizzo <a href="https://www.magazzinoperfetto.cloud">https://www.magazzinoperfetto.cloud</a>.' )); ?></p>

    <p><?php printf( __( 'Se non l\'hai già fatto, <b>scarica subito la nostra APP</b> dal Play Store <a href="#">cliccando qui</a> ed accedi inserendo i tuoi dati di accesso ed il <b>seguente PIN provvisorio:</b> ' )); ?></p>

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

我的问题是:如何在电子邮件中插入变量billing_pin?

抱歉我的英语不好..。我是意大利人。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-15 14:07:48

您可以使用get_user_meta()函数查找值并将其回显到电子邮件模板中。

代码语言:javascript
复制
<p>Billing Pin: <?php echo get_user_meta($order->user_id, 'billing_piva', true); ?></p>

将billing_piva字段替换为实际的键。我不知道你的钥匙到底是什么。

票数 0
EN

Stack Overflow用户

发布于 2020-10-02 07:58:17

您不需要编辑模板文件。只需在functions.php文件中添加新的变量即可。以下几点就可以了。

代码语言:javascript
复制
add_filter( 'woocommerce_email_format_string' , 'add_pin_format_string', 10, 4 );
function add_pin_format_string( $string, $email ) {
    $placeholder = '{pin}'; // The corresponding placeholder to be used
    $order = $email->object; // Get the instance of the WC_Order Object
    //$value = $order->get_customer_note();// Get the value
    $value = "PN000001";
    // Return the clean replacement value string for "{delivery_date}" placeholder
    return str_replace( $placeholder, $value, $string );
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44567745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档