Get products that contain 2 specific tag terms via WooCommerce REST API

43 Views Asked by At

I am trying to find a way to use the WooCommerce REST API to get products that contain two tags, I am having no luck while googling. I hope that someone can provide me some insights.

I have a query looking for two tag Ids and I need it to match. I have like 5000 products, so I don't really want to dump them then sort and woo only lets you pull 100 at a time, I'm also doing this based on a tag stored as a cookie for a location filter.

Here is what I am doing, but it is OR (not AND)… Does anyone know a workaround?

function getApiUrlByLocation(storeLocation) {
    var tagMapping = {
        'A-store': 334,
        'B-store': 357,
        'C-store': 333
    };

    // Modify the URL to fetch products with either tag 315 and the store-specific tag
    var apiUrlBase = 'https://www.URL GO HERE /wp-json/wc/v3/products?per_page=100&tag=315';
    if (storeLocation !== 'all-stores') {
        apiUrlBase += ',' + tagMapping[storeLocation];
    }

    return apiUrlBase;
}
0

There are 0 best solutions below