Skip to content

Instantly share code, notes, and snippets.

@kilbot
Created December 12, 2017 22:54
Show Gist options
  • Save kilbot/85bc63bc825990c2d6ebe4326c5bf11b to your computer and use it in GitHub Desktop.
Save kilbot/85bc63bc825990c2d6ebe4326c5bf11b to your computer and use it in GitHub Desktop.
Restrict WooCommerce POS Pro users to one (or more) stores
<?php
// the code below goes in your theme's functions.php file
function my_custom_pos_template_redirect() {
// a manual map of Store IDs => array of User IDs
$restrict = array(
1524 => array( 52, 863 ), // ie: Store ID 1524 restricted to User IDs 52 and 863
6252 => array( 863 ) // ie: Store ID 6252 restricted to User ID 863
);
// get current User ID & logged in Store ID
$user_id = get_current_user_id();
$store_id = get_user_option('woocommerce_pos_store');
// check User ID array exists and User ID in array, if not, display error
if( ! isset( $restrict[$store_id] ) || ! in_array( $user_id, $restrict[$store_id] ) ) {
wp_die( 'You do not have sufficient permissions to access this store.' );
}
}
// woocommerce_pos_template_redirect runs just before the POS template is rendered
add_action( 'woocommerce_pos_template_redirect', 'my_custom_pos_template_redirect', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment