Reputation: 121
I am trying to integrate the woocommerce rest APIs with my Applications. All the defaults operations like get all products, get products by category etc are working perfectly fine.
Can someone please let me know how are product filters implemented.?
bellow is my code.
$data = array(
'status' => 'publish',
'category' => '51',
'per_page' => 100,
'page' => 1,
'attribute' => "Color",
'attribute_term' => "Loft Gray"
);
$results = $woocommerce->get('products', $data)
Upvotes: 0
Views: 11632
Reputation: 561
Your question is really open ended. You don't have any code samples that show what you have working, such as when you say, "get products by category etc are working perfectly fine." What else do you need?
I can show you a couple examples, but who knows if it will help or not. I assume you already have a $woocommerce connection variable working...
Example 1:
$products = array();
$data = array(
'status' => 'publish',
'per_page' => 30,
'orderby' => 'date',
'order' => 'asc',
'featured' => 1
);
$products = $woocommerce->get('products', $data);//returns the first 30 featured products that are published, and sorts them by date
Example 2:
$results = array();
$data = array(
'status' => 'publish',
'category' => '51',
'per_page' => 100,
'page' => 1
//'filter[posts_per_page]' => '-1', //this was removed in v2 api
);
$results = $woocommerce->get('products', $data);//returns 100 published products of product category ID 51 (get this ID from your CMS)
//This can be used for pagination, since the filter functionality is removed
The API docs show you all the different properties you can access: http://woocommerce.github.io/woocommerce-rest-api-docs/?php#list-all-products
I hope this helps. If it doesn't, then please ask a specific question.
Upvotes: 4