【问题标题】:WooCommerce customer mail custom-get nameWooCommerce 客户邮件自定义获取名称
【发布时间】:2022-01-04 18:03:36
【问题描述】:

我有以下自定义表单,并将代码添加到 functions.php 文件中:

* ----------------------------------Checkout Field Stor data Start----------------------------------*/
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );

function my_custom_checkout_field_update_order_meta( $order_id ) {
    if ( ! empty( $_POST['account_per_title'] ) ) {
        update_post_meta( $order_id, ' Account Title', sanitize_text_field( $_POST['account_per_title'] ) );
    }
    if ( ! empty( $_POST['account_fname'] ) ) {
        update_post_meta( $order_id, 'Account First Name', sanitize_text_field( $_POST['account_fname'] ) );
    }
    if ( ! empty( $_POST['account_mname'] ) ) {
        update_post_meta( $order_id, 'Account Middle Name', sanitize_text_field( $_POST['account_mname'] ) );
    }
    if ( ! empty( $_POST['account_lname'] ) ) {
        update_post_meta( $order_id, 'Account Last Name', sanitize_text_field( $_POST['account_lname'] ) );
    }

在模板中我想显示填写订单的人的姓名:

<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html ($order->get_billing_first_name() ) ); ?></p>
<?php /* translators: %s: Order number */ ?>
<p><?php printf( esc_html__( 'Just to let you know — we\'ve received your order #%s, and it is now being processed:', 'woocommerce' ), esc_html( $order->get_order_number() ) ); ?></p>

谁能帮忙解决?

【问题讨论】:

  • 解决方案:add_filter('woocommerce_email_recipient_customer_processing_order', 'processing_order_replacement_email_recipient', 10, 2);函数 processing_order_replacement_email_recipient( $recipient, $order ) { if ( !is_a( $order, 'WC_Order' ) ) return $recipient; // 在此处设置您的替代收件人电子邮件...(如果有多个,用逗号分隔) $recipient = get_post_meta( $order->id, 'Account Email', true ) ;返回 $recipient; }

标签: woocommerce hook-woocommerce


【解决方案1】:

add_filter( 'woocommerce_email_recipient_customer_processing_order', 'processing_order_replacement_email_recipient', 10, 2 );
function processing_order_replacement_email_recipient( $recipient, $order ) {
    if ( ! is_a( $order, 'WC_Order' ) ) return $recipient;

    // Set HERE your replacement recipient email(s)… (If multiple, separate them by a coma)
    $recipient = get_post_meta( $order->id, 'Account Email', true ) ;
    return $recipient;
}

【讨论】:

    猜你喜欢
    • 2017-05-19
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 2018-09-21
    • 2019-01-13
    • 1970-01-01
    相关资源
    最近更新 更多