I am building a plugin that adds a new option to the the woocommerce order actions column on the orders page. To ensure this is used right, I want to programmatically make sure that the actions screen option (as in the column) is rendered. I have searched far and wide but I cannot find anything in this direction. Help would be greatly appreciated.
I have tried:
"unhiding" the actions tab by adding some javascript. This is not the way because there is a lot of dynamic content and this just messes up the interface.
installing Simply Show Hooks and try to find a hook or filter that I can hook into. This also did not have any success.
This hook is also not working: default_hidden_meta_boxes
I reckon it's such a simple thing to do, which makes it even more frustrating. Thanks in advance :)
ps. screenshot for clarification what i'm trying to enable
My solution is more based in which screen options want to be unchecked, but the same can work for the options to be checked, just not include these options.
Drop the following into your functions.php file and it will work perfectly. Remember to remove the conditional temporarily if the user has already set their preferences.
// 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 );
}
}
The $meta_key
value I found was doing the following query:
SELECT * FROM wp_usermeta WHERE meta_key LIKE '%hidden%'
The $meta_value
in this case are the ID values of each column, wc_actions
meta value was the one not to include.
You could find more info here: How to set default screen options?