Denis
Denis

Reputation: 29

WooCommerce API List all products with a specific attribute

Using the WooCommerce API I want to send an HTTP GET request to download all products with a specific attribute.

The documentation says the URL to do this with is this:

/wp-json/wc/v3/products

And I can add parameters to the URL in order to filter the products.

I have successfully added filters for page and page count:

wp-json/wc/v3/products?per_page=100&page=10

I have also managed to get only available products with this parameter:

wp-json/wc/v3/products?&stock_status=instock

However, I cannot manage to add a filter for the attributes. I have tried the following ways to write the URL and non of them work

wp-json/wc/v3/products/?attribute=1
wp-json/wc/v3/products/?
wp-json/wc/v3/products/?attribute_pa_емаг=Да
wp-json/wc/v3/products/?filter[pa_емаг]=10

What would be the correct way to write the URL?

(Note: The attribute is pa_емаг and its value is Да)

Upvotes: 0

Views: 2607

Answers (2)

JurijsReact
JurijsReact

Reputation: 150

With js API:

md.woo_products.read({
            "attribute": 'pa_package',
            "attribute_term": '97'})

Upvotes: 0

GhostPengy
GhostPengy

Reputation: 1024

The correct call would be:

/wp-json/wc/v3/products?attribute={attribute-taxonomy}&attribute_term={term-id/tag_ID}

Where attribute-taxonomy would be full slug in your case "pa_емаг", and term-id/tag_ID the id of "Да".

Upvotes: 4

Related Questions