最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - wc_get_products() return empty object

programmeradmin3浏览0评论

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)

  1. 暂无评论