wc_get_products() return empty object

Question

I’m trying to get all the products that exists in database, but my code return empty objects.
just for the sake of testing, first I’m trying to get only 10 products,
here is my code

add_action('rest_api_init', 'getProducts');
function getProducts()
{
    register_rest_route('products/v1/', 'allproducts', array(
        'methods' => WP_REST_Server::READABLE,
        'callback' => 'allProducts',
    ));
}
function allProducts()
{
    $products = wc_get_products(array(
        'limit' => 10
    ));
    return $products;
}
0
, , , Lint 1 year 2020-07-23T09:10:31-05:00 0 Answers 82 views 0

Leave an answer

Browse
Browse