2016-04-03 12 views
1

私はWooCommerceですべての製品データを取得したいと思っています(製品SKU、名前、価格、在庫数、在庫状況など)wp-queryを使用してこれを行うことはできますか?あなたの建物のうち、あなたのクエリは、製品にプログラムでWooCommerceのすべての製品を取得するには?

$query->set('post_type', 'product'); 

をするポストタイプを設定し、それが唯一のwoocommerce製品を検索します

+0

woocommerceプラグインでは、すべてのテンプルはすでに存在しており、カスタムのテンプレットにコードをコピーしていますあなたはカスタム投稿タイプのクエリを使用してポストメタメソッドを取得することもできます –

+2

フレンドリーなヒント、このページを読むことができます:[How-To-Ask Guide](https: //stackoverflow.com/help/how-to-ask)ので、質問を簡単に答えることができ、できるだけ明確にすることができます。あなたが抱えている問題を修正するためにあなたがした努力と、それらの修正を試みたときに何が起こったのかを必ず含めてください。あなたのコードやエラーメッセージも忘れないでください! –

+1

すべての製品データはポストメタです。しかし私はMatthewに同意します、あなたが何を求めているかははっきりしていません。 – helgatheviking

答えて

1

また、テーマを作成している場合は、/wp-content/plugins/woocommerce/templates/ディレクトリから任意のファイルを取り出し、/wp-content/themes/<yourTheme>/woocommerceの中に入れて、任意のwoocommerceページを上書きすることができます。

3

あなたがwp_query経由ですべての製品を得ることができるこの方法:すべてのreply.Iのおかげでは、決意を持っている

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

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'"); 

をそして、あなたはさらに、製品データを望むならば、それはこのようになりますそれはbillowsのように

$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; 
関連する問題