使用 Woocommerce 电子邮件中的自定义字段自定义格式化的账单全名 [英] Customize formatted billing full name with a custom field in Woocommerce emails

查看:26
本文介绍了使用 Woocommerce 电子邮件中的自定义字段自定义格式化的账单全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个网站上,我使用 WooCommerce 的灵活结账字段来创建 20 个自定义字段.其中两个需要是选择/下拉字段.我无法通过插件做到这一点(不想为此付费.现在后悔那个决定.这太可怕了);所以我使用 WooCommerce 中的名字和姓氏默认标签将它们变成一个选择字段.我用它们来选择名字前的先生/夫人头衔.

On one of my websites I use the Flexible Checkout Fields for WooCommerce to make 20 custom fields. Two of them needed to be a select/dropdown field. I wasn't able to do so via the plugin (didn't want to pay for it. Regret that decision now. It is horrible); so I used the first-name and last-name default tags from WooCommerce to make them into a select field. I use them to select the Mr/Mrs title before the name.

电子邮件现在只显示名字和姓氏字段,作为我想要的名字(选择先生/夫人头衔)和我的名字的新自定义字段.

The emails now only show the first-name and last-name fields, as where I would like to have the first-name (Mr/Mrs title select) and my new custom field for the first name.

我在 admin-new-order.php 中找到了下面的代码;<p><?php printf( __( '您收到了来自 %s 的订单.订单如下:', 'woocommerce' ), $order->get_formatted_billing_full_name() );?></p>

I found the code below in admin-new-order.php; <p><?php printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $order->get_formatted_billing_full_name() ); ?></p>

as where $order->get_formatted_billing_full_name() 将显示帐单名字和帐单姓氏.

as where $order->get_formatted_billing_full_name() will display the billing first-name and billing last-name.

有没有办法显示帐单名字和我的自定义字段?如果是这样,如何?

Is there a way to display billing first-name and my custom field? And if so, how?

提前致谢.

推荐答案

您需要在 emails/admin-new-order.php 模板中替换以下 (第 28 行):

You will need to replace in emails/admin-new-order.php template the following (on line 28):

 <p><?php printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $order->get_formatted_billing_full_name() ); ?></p>

通过此代码 (其中 _billing_voornaam_1_24 是您的自定义字段的元键):

By this code (where _billing_voornaam_1_24 is the meta_key of your custom field):

<p><?php 
    $formatted_full_name   = $order->get_billing_first_name();
    $formatted_full_name  .= ' ' . get_post_meta( $order->get_id(), '_billing_voornaam_1_24', true );
    $formatted_full_name  .= ' ' . $order->get_billing_last_name();

    printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $formatted_full_name ); ?></p>

如果订单的 _billing_voornaam_1_24 自定义字段存在,这应该可以工作......

This should work if _billing_voornaam_1_24 custom field exists for the order…

这篇关于使用 Woocommerce 电子邮件中的自定义字段自定义格式化的账单全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆