Created
February 9, 2018 02:41
-
-
Save kilbot/8592d96869b65e3057fc5a2f66112d5a to your computer and use it in GitHub Desktop.
Restrict POS products by store and category
This file contains hidden or 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 | |
// this goes in your functions.php file | |
function my_custom_pre_get_posts( $query ) { | |
// early exit if user is not in the POS | |
if( ! is_pos() ) { | |
return; | |
} | |
// a hard coded map of Store IDs => array of product categories | |
$restrict = array( | |
1524 => '52,863', // ie: Store ID 1524 restricted to category ids 52 and 863 | |
6252 => '-64,-863' // ie: Store ID 6252 excludes category ids 64 and 863 | |
); | |
// get current logged in POS store | |
$store_id = get_user_option( 'woocommerce_pos_store' ); | |
// if store is in restrict array, limit the products to mapped categories | |
if( ! isset( $restrict[$store_id] ) ) { | |
$query->set( 'cat', $restrict[$store_id] ); | |
} | |
} | |
add_action( 'pre_get_posts', 'my_custom_pre_get_posts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment