admin管理员组

文章数量:1291124

So, I've tried on my website. It works good, as long as all the products have SKU. If a product doesn't have SKU, it's not displayed at all.

This being said, is there any other way to sort by SKU but not require product to actually have SKU?

So, I've tried https://gist.github/bekarice/1883b7e678ec89cc8f4d on my website. It works good, as long as all the products have SKU. If a product doesn't have SKU, it's not displayed at all.

This being said, is there any other way to sort by SKU but not require product to actually have SKU?

Share Improve this question asked Jun 8, 2021 at 4:26 errorouserrorous 1691 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

To use with woocommerce plugin and theme already css and code.

$args = array(
            'post_type'      => 'product',
            'post_status'    => 'publish',
            'posts_per_page' => -1,
            'meta_key'       => '_sku',
            'orderby'        => 'meta_value',
            'order'          => 'DESC',
          );
query_posts( $args );
if( have_posts() ) :
  while (have_posts()): the_post();
    wc_get_template_part( 'content', 'product' );
  endwhile;
endif;
wp_reset_query();

本文标签: wp queryWooCommerce sort by SKU