Getting all woocommerce products from REST API call in plugin

I am developing a plugin that extends Woocommerce and acts as a custom product filter. The part I'm having trouble with is that it's not tied to one specific site, and has to fetch the products from an external API call, which is limited by 100 results per page, and I need just under 1000 products. I would prefer to get this data with one call only, without needing some hacky loop to glue together the results of the individual page calls. It seems that the only (recommended) way around this limit is to use some variation of the wc_get_products method, with the limit set to -1 to return all products. But I don't see how to apply that method without one clear parent site, and if I could do so, how to transform the API call function into a format that wc_get_products could read without initially limiting it to the first 100 product results.

Topic woocommerce-offtopic rest-api plugin-development plugins Wordpress

Category Web


I was close to the answer here, but held back by being unfamiliar with how global Wordpress can be, and how that can be used to extend plugins. All I needed to do was wrap the plugin logic in a check for the presence of Woocommerce:

if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
  // Stuff goes here
}

...and set the parameters for the search:

$args = array(
    'limit' => -1,
    'category' => array($category_slug),
    'tag' => array($tag_slug));
    $products = wc_get_products( $args );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.