Why wc_get_products() returns empty array?
I want to retrieve WooCommerce products from inside of the front-page.php
with the following code:
$args = array();
$products = wc_get_products($args);
So that I could could reiterate through them and output with a custom markup. However it returns an empty array, even though products do exist. When I use echo do_shortcode('[products]')
inside the front-page.php
, it returns products as expected. Shortcodes go with their own markups, so their use in my custom theme would be undesired. Also wc_get_product($id)
works fine to retrieve a single product.
I’ve tried passing arguments to wc_get_products()
, such as ['limit' => -1, 'status' => 'publish']
, but it still doesn’t work. What am I doing wrong?
Leave an answer