How to output a list of specific products only in woocommerce?

Member

by addison , in category: PHP CMS , a year ago

How to output a list of specific products only in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , a year ago

@addison 

To output a list of specific products only in WooCommerce, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$args = array(
    'post_type' => 'product',
    'post__in' => array(1, 2, 3), // Replace these numbers with the IDs of the specific products you want to output
);

$products = new WP_Query($args);

if ($products->have_posts()) {
    while ($products->have_posts()) {
        $products->the_post();
        wc_get_template_part('content', 'product');
    }
}

wp_reset_postdata();


You can add this code to your theme's functions.php file or create a custom shortcode to output the list of specific products on your WooCommerce site. Just replace the array of post IDs with the IDs of the specific products you want to display.

Related Threads:

How to list products by vendor id in woocommerce?
How to get specific words in an output of oracle query?
How to put capybara output html to a specific folder?
How to update price of all products in woocommerce?
How to display pagination for woocommerce products?
How to add variable tax on products in woocommerce?