• Resolved wiscomsolutions

    (@wiscomsolutions)


    Hello,
    I would like to only display products that have a certain meta value. I’m not super familiar with filters and how exactly they work. I have tried this but unfortunately without the desired results.

    add_filter('dgwt/wcas/search_query/args', function($args){
    
        $query = array(
          'meta_key'            => 'wwpp_product_wholesale_visibility_filter',
          'meta_value'          => 'wholesale_customer',
          'meta_compare'        => 'NOT LIKE'
        );
    
        if(!empty($args['meta_query'])){
            $args['meta_query'][] = $query;
        }else{
            $args['meta_query'] = array(
                'relation' => 'AND',
                $query
            );
    
        }
    
        return $args;
    
    });

    How would I achieve my goal?
    Thanks,
    Jeff

Viewing 1 replies (of 1 total)
  • Plugin Author Damian Góra

    (@damian-gora)

    Hi there,

    You have the wrong keys. Use the key, value, comprare instead of meta_key, meta_value, meta_compare. Here is corrected code:

    
    add_filter('dgwt/wcas/search_query/args', function($args){
    
        $query = array(
            'key'            => 'wwpp_product_wholesale_visibility_filter',
            'value'          => 'wholesale_customer',
            'compare'        => 'NOT LIKE'
        );
    
        if(!empty($args['meta_query'])){
            $args['meta_query'][] = $query;
        }else{
            $args['meta_query'] = array(
                'relation' => 'AND',
                $query
            );
    
        }
    
        return $args;
    
    });
    

    This code will work properly if a meta wwpp_product_wholesale_visibility_filter exists for every product.

    Best
    Damian Góra

Viewing 1 replies (of 1 total)
  • The topic ‘Only display products with meta value’ is closed to new replies.