如何以编程方式获取 WooCommerce 中的所有产品? [英] How to get all product in the WooCommerce programatically?

查看:30
本文介绍了如何以编程方式获取 WooCommerce 中的所有产品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取 WooCommerce 中的所有产品数据(产品 sku、名称、价格、库存数量、可用性等)我可以使用 wp-query 来做到这一点吗?

I want to get all the product data in the WooCommerce (product sku, name, price, stock count, availability and etc.) Can I do that using wp-query?

推荐答案

这样你就可以通过 wp_query 获取所有产品:

This way you can get all products via wp_query :

global $wpdb;

$all_product_data = $wpdb->get_results("SELECT ID,post_title,post_content,post_author,post_date_gmt FROM `" . $wpdb->prefix . "posts` where post_type='product' and post_status = 'publish'");

如果你想要更多的产品数据,那就是这样:

And if you want further product data then it will be like this :

$product = wc_get_product($product_id);
$product->product_type;
get_post_meta($prodyct_id, '_regular_price');
$product->get_available_variations();

这篇关于如何以编程方式获取 WooCommerce 中的所有产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆