我的解决方案更多基于要取消选中的屏幕选项,但同样适用于要选中的选项,只是不包括这些选项。
将以下内容放入您的functions.php 文件中,它将完美运行。如果用户已经设置了他们的偏好,请记住暂时删除条件。
// add_action('user_register', 'set_user_screen_options');
// This function will only fire when a new user is registered
add_action('admin_init', 'set_user_screen_options');
// Use this if you want it to work for users that already exist, just go to admin and reload once, then you can use only the function 'user_register'
function set_user_screen_options() {
$meta_key['hidden'] = 'manageedit-shop_ordercolumnshidden';
$meta_value = array(
'billing_address',
'shipping_address',
);
// set the default hiddens if it has not been set yet, you can remove this for testing, so it will work no matter the preferences saved
if ( ! get_user_meta( $user->ID, $meta_key['hidden'], true) ) {
update_user_meta( $user->ID, $meta_key['hidden'], $meta_value );
}
}
我发现的$meta_key 值正在执行以下查询:
SELECT * FROM wp_usermeta WHERE meta_key LIKE '%hidden%'
在这种情况下,$meta_value 是每列的 ID 值,wc_actions 元值是不包含的值。
您可以在这里找到更多信息:How to set default screen options?