[英]Add custom field variable in WooCommerce email
I have some custom variable for my WooCommerce user as:我的 WooCommerce 用户有一些自定义变量:
billing_pin
billing_piva
etc...等等...
When a new customer is created it receive an email of New Account and I have modified it.创建新客户时,它会收到一封新帐户的电子邮件,我已对其进行了修改。
For now my email is:现在我的电子邮件是:
<?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 );
My question is: How do I do to insert the variable billing_pin in email?我的问题是:如何在电子邮件中插入变量 billing_pin?
Sorry for my bad English... I'm Italian.抱歉我的英语不好……我是意大利人。
You do not need to edit the template file.您不需要编辑模板文件。 Just add the new varibale in functions.php file.
只需在functions.php 文件中添加新变量。 The following will do.
下面会做。
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 );
}
You could use the get_user_meta() function to find the value and echo this into the email template.您可以使用 get_user_meta() 函数查找值并将其回显到电子邮件模板中。
<p>Billing Pin: <?php echo get_user_meta($order->user_id, 'billing_piva', true); ?></p>
Replace the billing_piva field with whatever the key actually is.用实际的密钥替换 billing_piva 字段。 I'm not sure what your key is exactly.
我不确定你的钥匙到底是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.