• Hello there! Nice job with this plugin! Thank you!
    I have one question. We need to show single products from variations by one exact attribute. We know that there is no one function in your plugin to do it now. But we want to customize it. We have tried to make it in the code but something went wrong and no one product was showied. We tried to implement it with this snippet:

    class Woosv_Public {
    
        // ... existing code ...
    
        public function product_query( $args ) {
    
            $enable = get_option( 'woosv_enable', 'yes' );
    
            $args->set( 'woosv_filter', 'yes' );
    
            $args->set( 'post_type', [ 'product', 'product_variation' ] );
    
            $meta_query = (array) $args->get( 'meta_query' );
    
            if ( empty( $enable ) ) {
    
                $meta_query[] = [
    
                    'relation' => 'OR',
    
                    [
    
                        'key'     => '_variation_description',
    
                        'compare' => 'NOT EXISTS'
    
                    ],
    
                    [
    
                        'key'     => 'woosv_enable',
    
                        'value'   => 'enable',
    
                        'compare' => '=='
    
                    ],
    
                    [
    
                        'key'     => 'woosv_enable',
    
                        'value'   => 'reverse',
    
                        'compare' => '=='
    
                    ],
    
                ];
    
            } else {
    
                $meta_query[] = [
    
                    'relation' => 'OR',
    
                    [
    
                        'key'     => '_variation_description',
    
                        'compare' => 'NOT EXISTS'
    
                    ],
    
                    [
    
                        'key'     => 'woosv_enable',
    
                        'compare' => 'NOT EXISTS'
    
                    ],
    
                    [
    
                        'key'     => 'woosv_enable',
    
                        'value'   => 'default',
    
                        'compare' => '=='
    
                    ],
    
                    [
    
                        'key'     => 'woosv_enable',
    
                        'value'   => 'enable',
    
                        'compare' => '=='
    
                    ],
    
                ];
    
            }
    
            // add a condition for the color attribute taxonomy=pa_8-tsvet
    
            $meta_query[] = [
    
                'key'     => 'attribute_pa_8-tsvet',
    
                'compare' => 'EXISTS',
    
            ];
    
            // add a condition for the size attribute taxonomy=pa_1-razmernyj-kod
    
            $meta_query[] = [
    
                'key'     => 'attribute_pa_1-razmernyj-kod',
    
                'compare' => 'EXISTS',
    
            ];
    
            // Condition for excluding variations with a single attribute "pa_1-razmernyj-kod"
    
            $meta_query[] = [
    
                'relation' => 'AND',
    
                [
    
                    'key'     => 'attribute_pa_8-tsvet',
    
                    'compare' => 'EXISTS',
    
                ],
    
                [
    
                    'key'     => 'attribute_pa_1-razmernyj-kod',
    
                    'compare' => 'NOT EXISTS',
    
                ],
    
            ];
    
            $args->set( 'meta_query', $meta_query );
    
        }
    
        // ... existing code ...
    
    }

    Maybe can you help me to make it through the code?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • I have the same requirement too.. In our product We have two attributes Color and size… currently there is no way to tell the plugin to show variations only based on Color, instead what it is doing by design is show permutation combination of all the Variations based on Size too.

    Please share code to make the plugin work accordingly. Later it would be great if you can add that feature into the plugin.

    Hi @miheyeugene any success in getting this to work?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show a single product by an exact attribute’ is closed to new replies.