且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式获取 WooCommerce 中的所有产品?

更新时间:2023-01-30 07:38:35

这样你就可以通过 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();