Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Created January 31, 2024 16:04
Show Gist options
  • Save danielcharrua/92384f8067cd3cca0ea75f18a668524b to your computer and use it in GitHub Desktop.
Save danielcharrua/92384f8067cd3cca0ea75f18a668524b to your computer and use it in GitHub Desktop.
Create WordPress user with access only to WooCommerce Analytics
<?php
/*
* Add new role for Marketing Analytics in WooCommerce
*
* @author Daniel P. - charrua.es
*/
$analytics_role = add_role(
'manage_store_analytics',
'Analista de la tienda',
array(
'read' => true,
)
);
if ( null !== $analytics_role ) {
$analytics_role->add_cap("view_woocommerce_reports");
}
add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1);
function _wc_disable_admin_bar($prevent_admin_access) {
if (!current_user_can('manage_store_analytics')) {
return $prevent_admin_access;
}
return false;
}
add_filter('woocommerce_prevent_admin_access', '_wc_prevent_admin_access', 10, 1);
function _wc_prevent_admin_access($prevent_admin_access) {
if (!current_user_can('manage_store_analytics')) {
return $prevent_admin_access;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment