Last active
January 16, 2023 10:02
-
-
Save plugin-republic/bdcc4ffef8e1168caa0790fcb33b87e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Role-based check for grid view | |
*/ | |
function prefix_enable_grid_for_roles( $enable, $product_id ) { | |
$permitted_roles = array( 'administrator' ); | |
if( is_user_logged_in() ) { | |
$user = wp_get_current_user(); | |
$roles = ( array ) $user->roles; | |
if( empty( array_intersect( $permitted_roles, $roles ) ) ) { | |
// If the current user doesn't have any of the permitted roles, present the standard view | |
$enable = false; | |
} | |
} else { | |
// User is not logged in so present standard view | |
$enable = false; | |
} | |
return $enable; | |
} | |
add_filter( 'wcbvp_enable_variations_grid', 'prefix_enable_grid_for_roles', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment