繁体   English   中英

Woocommerce 设置计费字段值等于其他计费字段值

[英]Woocommerce set billing field value equal to other billing field value

我希望帐单字段“公司电子邮件”等于帐单电子邮件地址。

我认为这会奏效,但我只得到一个空字段:

add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1 );
    function custom_admin_billing_fields( $billing_fields ) {
        $billing_fields['tlr_company_email']['value'] = $billing_fields['email']['value'];
        return $billing_fields;
    }

在此处输入图片说明

我认为正确的做法是在付款完成后,在结帐后进行更新。 以下代码与支付完成触发器挂钩。 它将帐单电子邮件复制到自定义公司帐单电子邮件。

add_action('woocommerce_payment_complete', 'replicate_billing_email', 100, 1);

function replicate_billing_email($order_id){
    $order = new WC_Order($order_id); //obatin the completed order as object
    $billing_email = $order->get_billing_email(); //get the billing email address
    update_post_meta($order_id, 'tlr_company_email', $billing_email); //update the company email
    update_post_meta($order_id, '_tlr_company_email', $billing_email); //it maybe saved like that, with underscore, ommit if not needed
}

要测试它,请完成测试订单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM