WordPress.org

Ready to get started?Download WordPress

Forums

Groups
Groups to restrict Woo Products display (3 posts)

  1. jpajot
    Member
    Posted 10 months ago #

    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/

  2. jpajot
    Member
    Posted 10 months ago #

    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);
    
        }
    
    }
  3. itthinx
    Member
    Plugin Author

    Posted 9 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.