Woocommerce in-stock only with product filter

I have a function that is pulling only in-stock items in Woocommerce. It’s working properly but I need to be able to sort them alphabetically and then also have a dropdown filter so customers can filter through based on something (TBD). Here is the function I am using

function taxidermy_in_stock_products_shortcode() {

global $product, $woocommerce, $woocommerce_loop, $paged;
$columns =3;

$args = array(
‘post_type’ => ‘product’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1,
‘paged’ => get_query_var( ‘paged’ ),
‘orderby’ => ‘ASC’,
‘meta_query’ => array(
array(
‘key’ => ‘_stock_status’,
‘value’ => ‘instock’,
‘compare’ => ‘=’
)
)
);
$loop = new WP_Query($args);

ob_start();

woocommerce_product_loop_start();

while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( ‘content’, ‘product’ );
endwhile;

woocommerce_product_loop_end();

woocommerce_reset_loop();
wp_reset_postdata();

return ” . ob_get_clean() . ”;
}
add_shortcode( ‘in_stock_products’, ‘taxidermy_in_stock_products_shortcode’ );

I’m not sure what needs to be added or changed.

Read more here:: Woocommerce in-stock only with product filter

Leave a Reply

Your email address will not be published. Required fields are marked *