Some time requirement is to show specific randomly products instead of show all product that case we need to add to show using below code…
Note: product id’s(Get from products under WordPress dashboard), all variables are user defined you can change as per your consideration 🙂
$args = array(
'order' => 'ASC', //you can update here DESC
'include' => array( 4249, 4254, 4266, 4256, 4261, 4264, 4284, 4274, 4276, 4279 ), // this is product id’s
);
$all_products = wc_get_products( $args );
print_r($all_products); //You can see all products list here with preview
if ( $all_products ) { // product found then display below data
foreach( $all_products as $product) {
echo $pid = $product->id; //Get id of each product
echo $title = $product->get_title(); //Get title of each product
echo $price = $product->get_price(); //Get price of each product
}
}
else {
echo 'No Products'; // product not found then show below message
}