首页 文章

使用Woocommerce电子邮件中的自定义字段自定义格式化的结算全名

提问于
浏览
1

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

电子邮件现在只显示名字和姓氏字段,因为我希望有第一个名字(Mr / Mrs title select)和我的第一个名字的新自定义字段 .

我在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>

$order->get_formatted_billing_full_name() 将显示开票第一名和开票姓氏 .

有没有办法显示结算名字和我的自定义字段?如果是这样,怎么样?

提前致谢 .

1 回答

  • 1

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

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

    By this code (其中 _billing_voornaam_1_24 是自定义字段的meta_key):

    <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 自定义字段,这应该有效...

相关问题