• Resolved Pawe? Knapek

    (@adpawl)


    [products skus="foo, bar, baz"] -list all products. ??

    Problem is class-wc-shortcodes.php on line 351

    // Ignore catalog visibility
    $query_args['meta_query'] = WC()->query->stock_status_meta_query();

    -this line overwrite previous meta_query.

    e.g. fix:
    $query_args['meta_query'][] = WC()->query->stock_status_meta_query();

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    @adpawl I think this is the problem I am experiencing but I don’t totally understand what you said. Would you be willing to elaborate?

    Are you saying this line $query_args[‘meta_query’][] = WC()->query->stock_status_meta_query(); should replace class-wc-shortcodes.php on line 351 ?

    Thread Starter Pawe? Knapek

    (@adpawl)

    @benjaminpschultz, this is part of class-wc-shortcodes.php ( WC v3.6 ) – line 343-352:

    if ( ! empty( $atts['skus'] ) ) {
    			$query_args['meta_query'][] = array(
    				'key'     => '_sku',
    				'value'   => array_map( 'trim', explode( ',', $atts['skus'] ) ),
    				'compare' => 'IN'
    			);
    
    			// Ignore catalog visibility
    			$query_args['meta_query'] = WC()->query->stock_status_meta_query();
    		}

    But line 351 override $query_args[‘meta_query’] defined on line 344-348.

    Simple fix is change line 351 (and identical 358) to:
    $query_args['meta_query'][] = WC()->query->stock_status_meta_query();
    or (Mike sugestion):
    $query_args['meta_query'] = array_merge( $query_args['meta_query'], WC()->query->stock_status_meta_query() );

    Thanks, that was very helpful. I am going to try this solution and see what happens.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘2.6 Products shortcode problem (by SKU)’ is closed to new replies.