WordPress Development Asked on December 12, 2021
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;
}
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP