WordPress.org

Support

Support » Plugins and Hacks » Groups to restrict Woo Products display

Groups to restrict Woo Products display

  • Hi,
    So far groups is working well.
    My only issue is that Groups is correctly hiding the products in my Woocommerce Shop page, BUT for it does not change the query, the counters and categories displayed in the sidebar are those of the full unfiltered query. So the user will see information that is not permitted.

    Can I put some code somewhere in a woo templates (in the archive-product.php maybe?) to filter the query with groups permissions.

    Thanks for your help,
    Julien

    http://wordpress.org/plugins/groups/

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve found a snippet that might be reusable if you put me on the track to replace the “sale_item” filter with the “groups_permission” filter.
    The filter should get the permissions of the current user and query the products accordingly.
    Not sure though in which files I should put this snippet…

    add_action('pre_get_posts','sale_items');
    function sale_items($query) {
    
        if (!is_admin() && ($query->is_post_type_archive( 'product' ) || $query->is_tax( get_object_taxonomies( 'product' ))) && isset($_GET['sale']) && $_GET['sale'] == 1) {
    
             $meta_query = array(
    
                   array(
    
                       'key' => '_sale_price',
    
                       'value' => 0,
    
                       'compare' => '>',
    
                       'type' => 'numeric'
    
                   )
    
             );
    
             $query->set('meta_query',$meta_query);
    
        }
    
    }
    Plugin Author itthinx

    @itthinx

    Hi Julien, are you using the latest version of Groups? Just to make sure that this isn’t already covered …

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Groups to restrict Woo Products display’ is closed to new replies.