admin管理员组文章数量:1333434
we are developing a complex Woocommerce website and an app which uses V3 API.
Being sold products very valuable, we need to know the ordinal number of a purchase for each product. For example, we'd like to know that Alice was the third to buy that product and Bob the fifth and so on. What I can think of is to get the total sales through Woocommerce API for that product, then loop every order containing that product and order them by date. The problem is that this way is very time and resources consuming, especially having to loop through all the orders. Does anybody know a better approach. I don't ask for the code, but I'd be glad if someone could have a brilliant approach to share.
Thanks! Fabio
we are developing a complex Woocommerce website and an app which uses V3 API.
Being sold products very valuable, we need to know the ordinal number of a purchase for each product. For example, we'd like to know that Alice was the third to buy that product and Bob the fifth and so on. What I can think of is to get the total sales through Woocommerce API for that product, then loop every order containing that product and order them by date. The problem is that this way is very time and resources consuming, especially having to loop through all the orders. Does anybody know a better approach. I don't ask for the code, but I'd be glad if someone could have a brilliant approach to share.
Thanks! Fabio
Share Improve this question asked Jul 4, 2020 at 19:23 Fabio RicciFabio Ricci 1032 bronze badges1 Answer
Reset to default 1Assuming you are not allowed guest checkout what you can try is
- add a custom field to your WooCommerce products in which you would save the history of purchases as an array like
[<user_id_1>, <user_id_2>, ...]
; - write a custom function and use a
woocommerce_order_status_completed
hook to update this field according to products within the order (see this question for information on how to get user ID from the WooCommerce order); - write a function which will do a loop through all already placed orders and initialize that field value for each of your products.
This can be done as a plugin where initialization of this custom field will occur during plugin activation. And with the same plugin you could register an additional REST API endpoint.
本文标签: apiWoocommercefinding the ordinal number of a purchase for a certain product
版权声明:本文标题:api - Woocommerce, finding the ordinal number of a purchase for a certain product 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742292394a2448050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论