【问题标题】:Unable to use WooCommerce custom field as recipient in custom email无法在自定义电子邮件中使用 WooCommerce 自定义字段作为收件人
【发布时间】:2016-03-14 22:43:39
【问题描述】:

我想要完成的是在新的自定义电子邮件中使用结帐中的自定义字段。我在returning the key, value within the body of the email 和订单详细信息中找到了文档,这些文档有效。

问题是我无法让它与新的自定义订单通知一起使用,我想使用“备用电子邮件”作为自定义电子邮件通知的收件人。

 /** WORKING
 * Add the field to order emails
 **/
add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');

function my_woocommerce_email_order_meta_keys( $keys ) {
    $keys['back-up email?'] = 'backup_email';
    return $keys;
}
/** WORKING
 * Add to back-end
 **/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );

function my_custom_checkout_field_display_admin_order_meta($order){
     echo '<p><strong>'.__('Back-up Email').':</strong> ' . get_post_meta( $order->id, 'backup_email', true ) . '</p>';
}

使用此tutorial 创建自定义电子邮件。

// Does not work
$this->recipient = get_post_meta( $order->id, 'backup_email', true );
// defaults to admin email
if ( ! $this->recipient )
        $this->recipient = get_option( 'admin_email' );

我可能缺少一些基本的 PHP/WP 原则,所以请赐教。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    想通了。需要在设置新的订单对象后调用

    $this->object = new WC_Order( $order_id );
    $this->recipient = get_post_meta( $order_id, 'backup_email', true );
    

    我看到这个问题已经被问过几次了,所以希望它对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-02-25
      • 2022-01-14
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      • 2016-05-19
      相关资源
      最近更新 更多