how to create woocommerce only order manager access - woocommerce

I'm trying to create a role in my wordpress that could manage orders (edit, delete, read and change status)
I'm using user role editor plugin in my woocommerce,
also tried:
edit_shop_order
edit_shop_orders
edit_published_shop_orders
edit_private_shop_orders
edit_others_shop_orders
read_shop_order
shop_order
view_admin_dashboard
woocommerce_order_itemmeta
woocommerce_order_items
woocommerce_view_order
the problem is if i don't check manage_woocommerce there is no orders to display, but if I check it, all orders displays correctly bud woocommerce setting is also shown.
Can everyone help me by doing this programmatically or in user role editor plugin?

By adding this code you can disable other woocommerce setting menus and active only orders menu:
add_action( 'admin_menu', 'remove_menu_pages', 999);
function remove_menu_pages() {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if($user_role == "orders_manager") {
$remove_submenu = remove_submenu_page('woocommerce', 'wc-settings');
$remove_submenu = remove_submenu_page('woocommerce', 'wc-addons');
$remove_submenu = remove_submenu_page('woocommerce', 'wc-status');
}
}

Related

Allow Woocommerce shop manager to assign a role when creating a user

The custom role shop manager created by Woocommerce can only assign the customer role when adding a user.
I'm trying to let shop manager choose from the different roles by enabling the capability promote_users.
function shop_manager_add_users() {
$role = get_role( 'shop_manager' );
$role->add_cap( 'promote_users' );
}
add_action( 'admin_init', 'shop_manager_add_users');
It's not working, the selection drop down only offers the customer role, and other roles are still hidden.
Is there another capability that should be enabled?
Actually Woocommerce adds specific restrictions to the Shop Manager role.
This worked and allowed a consigner custom role to be available in the dropdown :
function shop_manager_role_edit_cap( $roles ) {
$roles[] = 'consigner';
return $roles;
}
add_filter( 'woocommerce_shop_manager_editable_roles', 'shop_manager_role_edit_cap' );
Source: developer.woocommerce.com/

Show only user-created taxonomy entries

iam implementing an event system on wordpress which allows an restricted user the following:
Create a new organizer (custom-post-type)
Create an event (custom-post-type)
Creating an event the user should choose an organizer for a special event by a list. Therefore i handle the organizer cpt as a taxonomy inside the event cpt.
Now my question is:
How can i only show the organizers, which this specific user has created? I face the problem, that all existing events are shown on every event for every user.
If you need any code or screenshots let me know, thank you very much in advance!
Solved it with Advanced Custom Fields plugin (Relationship Field). It is possible to relate cpts into another cpt. I learned to NOT use a cpt as a taxonomy.
Approach for filtering only user created posts
You can achieve it by adding the following code to your functions.php file
function posts_for_current_author($query) {
global $pagenow;
if( 'edit.php' != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( 'edit_others_posts' ) ) {
global $user_ID;
$query->set('author', $user_ID );
}
return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');

Hide specific dashboard items for user in Wordpress

In my website dashboard i have to hide Media, Comments, Contact menu items for one user who has administrator role. I googled that I have to use remove_cap function, but couldn't find enough information even to start my task.
You can put something like this inside your functions.php. :
add_action( 'admin_menu', 'adjust_the_wp_menu', 999999 );
function adjust_the_wp_menu() {
$user = wp_get_current_user();
if($user && isset($user->user_login) && 'desired_user_login' == $user->user_login)
{
//Remove menu items from admin area
remove_menu_page( 'edit-comments.php' );//For comments
remove_menu_page( 'upload.php' );//For media
//Remove third party plugins admin menu items
remove_menu_page( 'edit.php?post_type=your_custom_post_slug' );//for custom posts
remove_menu_page( 'your_plugin_page_slug' );//for custom plugin's page
// do stuff
}
}
Not sure what is the Contact menu in your Wordpress. I guess it is added by some plugin. You can try to figure out it's slug & use it inside the code above.
Also note, that it will only hide the menu items. Pages itself will be still available if respective url is accessed directly. To prevent this you should manage user roles or put some conditional logic into your functions.php.

Only logged in users should be able to view product in WooCommerce

I want to restrict WooCommerce products, shop page and category pages to logged in users only.
I do not want to achieve it with any plugin.
Please let me know if anybody done it before with any hook/filter/action.
Or I have to make WooCommerce template pages and add condition over there.
If I was to do this I would hook into the init action that WordPress offers.
Then do something like this in your theme's functions.php file:
function woo_check_logged_in()
{
if ( (is_product() || is_shop() ) && is_user_logged_in() )
{
}
else
{
die("You must be logged in to view this page");
}
}
add_action('init', 'woo_check_logged_in');
I haven't tested this but I believe it should get you on the right path without having to use any plugins.

Restricting Wordpress Admin Options to Admins

I thought this would be an easy thing but many hours have gone by and still no results.
I am creating a Wordpress plug-in that should only appear in the dashboard if the user is an admin. I wrapped my hooks in the is_admin() method, but when I log in as a user who is just a subscriber, I still see the menu.
Isn't it just that easy???
Here's a code except starting right below the comment section to register the plugin... everything not shown is just functions doing their job ...
if( is_admin ){
add_action('admin_menu', 'ppm_talentexpo_add_page');
add_action('admin_menu', 'ppm_expos_submenu');
} // end is_admin
function ppm_talentexpo_add_page() {
$mypage = add_menu_page('Talent Expo', 'Talent Expos', 2, 'ppmtalentexpo', 'jwg_talentexpo_options_main_page', '/wp-admin/images/media-button-music.gif' , 21);
add_action( "admin_print_scripts-$mypage", 'jwg_ppmtalentexpo_admin_head' );
} // end function
It looks like you left out the parentheses when calling is_admin in the conditional.
Try
if( is_admin() ){
add_action('admin_menu', 'ppm_talentexpo_add_page');
add_action('admin_menu', 'ppm_expos_submenu');
}
Also if you're not using an older WordPress install, add_menu_page allows you to specify a capability that WordPress will check for. This lets WordPress manage showing the item or not.
So you can define a custom capabilty (or reuse an existing one), and the menu should take care of itself.
add_action('admin_menu', 'ppm_talentexpo_add_page');
add_action('admin_menu', 'ppm_expos_submenu');
function ppm_talentexpo_add_page() {
$mypage = add_menu_page('Talent Expo', 'Talent Expos', 'my_custom_talent_expos_capability', 'ppmtalentexpo', 'jwg_talentexpo_options_main_page', '/wp-admin/images/media-button-music.gif' , 21);
add_action( "admin_print_scripts-$mypage", 'jwg_ppmtalentexpo_admin_head' );
}

Resources