我想要获得WooCommerce中的所有产品数据(产品sku,名称,价格,库存量,可用性等)我可以使用wp-query来完成这项工作吗?如何以编程方式获取WooCommerce中的所有产品?
1
A
回答
1
当你建设了查询设置的岗位类型为产品
$query->set('post_type', 'product');
而这只能通过woocommerce产品搜索。
另外,如果您要创建主题,则可以从/wp-content/plugins/woocommerce/templates/
目录中取出任何文件,并将其放入/wp-content/themes/<yourTheme>/woocommerce
以覆盖任何woocommerce页面。
3
这样,您就可以通过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'");
如果你想了解更多的产品数据,那么这将是这样的:
$product = wc_get_product($product_id);
$product->product_type;
get_post_meta($prodyct_id, '_regular_price');
$product->get_available_variations();
1
感谢所有reply.I有决心就像波涛汹涌
$full_product_list = array();
$loop = new WP_Query(array('post_type' => array('product', 'product_variation'), 'posts_per_page' => -1));
while ($loop->have_posts()) : $loop->the_post();
$theid = get_the_ID();
$product = new WC_Product($theid);
if (get_post_type() == 'product_variation') {
// ****************** end error checking *****************
} else {
$sku = get_post_meta($theid, '_sku', true);
$selling_price = get_post_meta($theid, '_sale_price', true);
$regular_price = get_post_meta($theid, '_regular_price', true);
$description=get_the_content();
$thetitle = get_the_title();
}
// add product to array but don't add the parent of product variations
if (!empty($sku))
$full_product_list[] = array("PartyID" => (int) $party_id,"Description"=> $description,
"ExternalNumber" => $theid, "ProductName" => $thetitle, "sku" => $sku,
"RegularPrice" => $regular_price, "SellingPrice" => $selling_price,
"ExternalProductCategoryId" => $cat_id, "ExternalProductCategoryName" => $cat_name);
endwhile;
相关问题
- 1. 以编程方式隐藏Woocommerce产品
- 2. 如何以编程方式获取MSI产品版本的C#
- 3. 如何在WooCommerce中以随机顺序获取所有产品的变体
- 4. 如何以编程方式在WooCommerce中添加新的定制产品属性?
- 5. 获取woocommerce类别中的所有产品ID
- 6. 如何以编程方式设置新Woocommerce产品创建的类别?
- 7. 以编程方式更新所有产品属性
- 8. 以编程方式获取Magento产品URL后缀?
- 9. Eclipse RCP:如何以编程方式从产品文件中获取版本号?
- 10. 如何在运输方式中获取产品的编号
- 11. 获取来自多个类别的所有产品(Woocommerce/Wordpress)
- 12. 获取英文版本的所有产品 - WooCommerce&WPML
- 13. 以编程方式为WooCommerce中的产品添加更多可下载文件
- 14. WooCommerce产品中的自定义插件,并以编程方式订购
- 15. 如何以编程方式从库文件获取产品密钥标记?
- 16. WooCommerce:排除所有产品中的近期产品
- 17. 通过WooCommerce中的产品ID获取产品标签
- 18. 按照产品类别在WooCommerce的简码中获取产品
- 19. 如何以编程方式在Magento中设置产品属性?
- 20. WooCommerce获取所有产品作为ID名称对
- 21. WooCommerce Custom Loop从一个特定类别获取所有产品
- 22. 以编程方式在Woocommerce中打开特定产品选项卡
- 23. 取子产品woocommerce
- 24. 以编程方式获取Magento中产品图像的宽度和高度?
- 25. 以编程方式获取DNN中的所有朋友
- 26. 如何以编程方式更改项目的产品版本?
- 27. WooCommerce以不同价格以编程方式添加产品变体不会反映在产品页面上
- 28. 获取可用AWS产品列表的编程方式?
- 29. WooCommerce - 获取产品页面的类别
- 30. 无法获得WooCommerce中的所有产品
在woocommerce插件的所有模板已经存在找到它并将代码复制到您的自定义模板e ..他们是用meta添加的自定义帖子类型u也可以使用自定义帖子类型查询并获得帖子meta方法 –
只是一个友好的提示,您可能想要阅读本页:[如何提问](https: //stackoverflow.com/help/how-to-ask),因此您始终可以确定您的问题很容易回答并尽可能清晰。一定要包括你为解决你遇到的问题所做的任何努力,以及当你尝试修复这些问题时发生了什么。另外不要忘记你的代码和任何错误信息! –
所有产品数据为后期元。但我同意马修的意见,不清楚你在问什么。 – helgatheviking