【问题标题】:Clear checkout fields for specific user(s) in WooCommerce清除 WooCommerce 中特定用户的结帐字段
【发布时间】:2021-03-14 13:45:53
【问题描述】:
此代码为所有人清除结帐页面的所有输入。我想清除特定用户的所有输入。我该怎么做。
add_filter( 'woocommerce_checkout_get_value' , 'clear_checkout_fields' );
function clear_checkout_fields($input)
{
return '';
}
【问题讨论】:
标签:
php
wordpress
woocommerce
hook-woocommerce
userid
【解决方案1】:
对于已定义的用户ID,您可以使用(在IF语句中设置相关的用户ID):
add_filter( 'woocommerce_checkout_get_value', 'clear_checkout_fields' );
function clear_checkout_fields( $input ) {
if ( get_current_user_id() == 259 ) {
return '';
}
return $input;
}
或者对于一组用户ID:
add_filter( 'woocommerce_checkout_get_value', 'clear_checkout_fields' );
function clear_checkout_fields( $input ) {
if ( in_array( get_current_user_id(), array( 259, 321, 336 ) ) {
return '';
}
return $input;
}