如何在下订单后清除 WooCommerce 账单电子邮件和账单 phone 结帐字段?

How to clear WooCommerce billing email and billing phone checkout fields after place order?

如何在下订单后清除 WooCommerce 中的特定结帐字段?

例如 Billing emailBilling Phone。这样当注册客户 his/her 下一个订单时,he/she 必须再次填写该字段?

我看到这段代码,但是它清除了所有字段,我只需要一个特定字段。有什么建议吗?

add_filter('woocommerce_checkout_get_value','__return_empty_string',10);

您可能可以通过一些自定义来实现此目的 javascript:

document.getElementById('fieldID').value = ''

或jQuery:

$('#fieldID').val('');

woocommerce_checkout_get_value 钩子有 2 个参数:

  • $value 返回的参数
  • $input 目标结帐字段的参数

所以在你的情况下,你得到:

function filter_woocommerce_checkout_get_value( $value, $input ) {
    // Target checkout fields. Multiple fields can be added, separated by a comma
    if ( in_array( $input, array( 'billing_phone', 'billing_email' ) ) ) {
        $value = '';
    }

    return $value;
}
add_filter( 'woocommerce_checkout_get_value' , 'filter_woocommerce_checkout_get_value' , 10, 2 );