Issue
Good day experts,
Please I need your help, I created a method that fetches all Woocommerce products to my ionic app using Woocommerce API.
Please how do I fetch only products that are in-stock?
woocommerce.service.ts
//get all Products
getAllProducts(){
this.apiUrl = `${this.siteUrl}${this.woocommercePath}products?per_page=11&consumer_key=${this.consumerKey}&consumer_secret=${this.consumerSecret}`
console.log(this.apiUrl);
this.products = this.http.get(this.apiUrl).pipe( retry(1),catchError(this.handleError) );
return this.products;
}
products.html
<ion-row class="container">
<ion-col size="6" *ngFor="let product of products" >
<ion-card >
<img src="{{ product.images[0].src }} "/>
<ion-card-header>
<ion-card-title>{{ product.name }}</ion-card-title>
</ion-card-header>
<ion-card-content>
<ion-label>
<h3>Price: {{ product.price | number:'1.0-0' }}</h3>
</ion-label>
</ion-card-content>
<ion-button size="small" expand="full" color="success" >
Order
</ion-button>
</ion-card>
</ion-col>
</ion-row>
Solution
Add stock_status=instock
to the url to limit the search for only instocked products....
${this.siteUrl}${this.woocommercePath}products?per_page=11&consumer_key=${this.consumerKey}&stock_status=instock&consumer_secret=${this.consumerSecret}
Answered By - Sajjad Hossain Sagor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.