LoginSignup
3
3

More than 5 years have passed since last update.

WooCommerceの商品情報を取ってくる

Last updated at Posted at 2016-02-25

wc_get_productに商品のIDを投げる

2番目の引数に投げる値については調べているところなのでちょっとわからない

wc_get_product( $post_id, array() );

#ID=2115の商品オブジェクトを取ってくる
wc_get_product( 2115 );

戻り値はこんな感じのオブジェクト

class WC_Product_Simple#8606 (7) {
  public $id =>
  int(2115)
  public $post =>
  class WP_Post#342 (24) {
    public $ID =>
    int(2115)
    public $post_author =>
    string(1) "1"
    public $post_date =>
    string(19) "2016-02-25 18:36:16"
    public $post_date_gmt =>
    string(19) "2016-02-25 09:36:16"
    public $post_content =>
    string(883) "■商品説明

商品説明文がここに入ります。"...
    public $post_title =>
    string(91) "商品名 【国内正規品】"
    public $post_excerpt =>
    string(124) "<table>
<tr><th>メーカー型番</th><td>XXXXX</td></tr>
<tr><th>カラー</th><td>Baltic Birch</td></tr>
</table>"
    public $post_status =>
    string(7) "publish"
    public $comment_status =>
    string(4) "open"
    public $ping_status =>
    string(6) "closed"
    public $post_password =>
    string(0) ""
    public $post_name =>
    string(187) "meinl-percussion-"
    public $to_ping =>
    string(0) ""
    public $pinged =>
    string(0) ""
    public $post_modified =>
    string(19) "2016-02-25 18:36:16"
    public $post_modified_gmt =>
    string(19) "2016-02-25 09:36:16"
    public $post_content_filtered =>
    string(0) ""
    public $post_parent =>
    int(0)
    public $guid =>
    string(45) "http://woo.dev/?post_type=product&#038;p=2115"
    public $menu_order =>
    int(0)
    public $post_type =>
    string(7) "product"
    public $post_mime_type =>
    string(0) ""
    public $comment_count =>
    string(1) "0"
    public $filter =>
    string(3) "raw"
  }
  public $product_type =>
  string(6) "simple"
  protected $shipping_class =>
  string(0) ""
  protected $shipping_class_id =>
  int(0)
  public $total_stock =>
  NULL
  protected $supports =>
  array(1) {
    [0] =>
    string(16) "ajax_add_to_cart"
  }
}


参考

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3