One my client want to display all woocommerce product by product SKU.
Normally i used following code for display products.
$postArg = array('post_type'=>'product',
                            'post_status'=>'publish',
                            'posts_per_page'=>-1,
                            'orderby'=>'data',
                            'order'=>'DESC',
                    );
            $queryGetFiles = get_posts($postArg);
But now my client want to show all products by product SKU in front side.
SKU like this 1041-14, 1041-12, 1041-16 ,1041,2001,3501
all product has different sku value and display which doesn't have "-" character
Anyone know how should i do this?
Try this
$postArg = array(
       'post_type'      => 'product',
       'post_status'    => 'publish',
       'posts_per_page' => -1,
       'meta_key'       => '_sku',
       'orderby'        => 'meta_value' // meta_value_num if ordered by intergers
       'order'          => 'DESC',
);
$queryGetFiles = get_posts($postArg);
Answered with help of this post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With