[WordPress] Woocoomerce 製品の属性を取得する方法

スポンサーリンク

Question

多くのコードを試しているし、woocommerce 製品の属性を取得関数カート ページ.

function mycustom()
{
  global $woocommerce;
  $cart = $woocommerce->cart->get_cart();
    foreach($cart as $key => $value)
    {
                $price = $value['data']->price;
                echo $price;
    }

}

このコードでは、価格が製品属性を必要があります

var_dump($cart) を返します

array(1) {[“71abc9824e5d1f7ec18d323a87e8d4a9″] = > array(10) {[“product_id”] = > 以降「87」[“variation_id”] = > 以降「89」[「バリエーション」] = > array(5) {[「デザイン」] = > と”Custom_54a65f2320a149″[「タイプ」] = >「カスタム」[“wbfd_type”] string(6) = > string(11)”wbfd_custom”[“wbfd_custom_price”] = > 以降「12」[「カードの番号」] = > 以降「50」} [「数量」] = > int (1) [「データ」] = > オブジェクト (WC_Product_Variation) # 121 (18) {[“variation_id”] = > int(89) [「親」] = > オブジェクト (WC_Product_Simple) #117 (3) {[“id”] => int(87) [“post”] = > オブジェクト (WP_Post) #120 (24) {[“ID”] = > int(87) [“post_author”] = > となります「2」[“post_date”] = > string(19)”2015年-01-02 5:31:53″[“post_date_gmt”] = > string(19)”2015年-01-02 5:31:53″[“post_content”] = > string(0)””[“post_title”] = > string(26)”ベビー シャワーの招待状 B1″[“post_excerpt”] = > string(0)””[“post_status”] = > string(7)「公開」[“comment_status”] = > 以下「オープン」[“ping_status”] = > string(6) の「クローズド」[“post_password”] = > string(0)””[“post_name”] = >string(28)「赤ちゃん-シャワー-招待状-b1-2」[“to_ping”] = > string(0)””[「ping を実行」] = > string(0)””[“post_modified”] = > string(19)”2015年-01-02 6:15:51″[“post_modified_gmt”] = > string(19)”2015年-01-02 6:15:51″[“post_content_filtered”] = > string(0)””[“post_parent”] = > int(0) [“guid”] = > string(58)” http://example.com“[“menu_order”] = > int(0) [“post_type”] = > string(7)「製品」[“post_mime_type”] = > string(0)””[“comment_count”] = > となります「0」[「フィルター」] = > と「生」} [“product_type”] = > string(6)「単純な」} [“variation_shipping_クラス”] = > bool(false) [“variation_shipping_class_id”] = > bool(false) [“variation_has_sku”] = > bool(true) [“variation_has_length”] = > bool(true) [“variation_has_width”] = > bool(true) [“variation_has_height”] = > bool(true) [“variation_has_weight”] = > bool(true) [“variation_has_tax_class”] = > bool(true) [“variation_has_downloadable_files”] = > bool(true) [“variation_level_meta_data: 保護された”] = > array(11) {[「ダウンロード」] = > 以降”no”[「仮想」] = > 以降「ノー」[“manage_stock”] = > 以降「ノー」[“sale_price_dates_from”] = > string(0)””[“sale_price_dates_to”] = > string(0)””[「価格」] = > string(0)””[“regular_price”] = > string(0)””[“sale_price”] = > string(0)”」【「株価」】 = > int(0) [“stock_status”] = > string(7)”instock”[“downloadable_files”] = > array(0) {}} [“variation_inherited_meta_data: 保護”] = > array(7) {[“tax_class”] = > string(0)””[「残」] = > 以降”ノー”[“sku”] = > string(0)””[“重量”] = > string(0)””[“長さ”] = > string(0)””[“幅”] = > string(0)””[“高さ”] = > string(0)””} [“id”] = > int(87) [“post”] = > オブジェクト (WP_Post) #120 (24) {[“ID”] = > int(87) [“post_author”] = > となります「2」[“post_date”] = > string(19)”2015年-01-02 5:31:53″[“post_date_gmt”] = > string(19)”2015年-01-02 5:31:53″[“post_content”] = > string(0)””[“post_title”] = > string(26)”ベビー シャワーの招待状 B1″[“post_excerpt”] = > string(0)””[“post_status”] = > string(7)「公開」[“comment_status”] = > 以下「オープン」[“ping_status”] = > string(6) の「クローズド」[“post_password”] = > string(0)””[“post_name”] => string(28)「赤ちゃん-シャワー-招待状-b1-2」[“to_ping”] = > string(0)””[「ping を実行」] = > string(0)””[“post_modified”] = > string(19)”2015年-01-02 6:15:51″[“post_modified_gmt”] = > string(19)”2015年-01-02 6:15:51″[“post_content_filtered”] = > string(0)””[“post_parent”] = > int(0) [“guid”] = > string(58)” http://example.com“[“menu_order”] = > int(0) [“post_type”] = > string(7)「製品」[“post_mime_type”] = > string(0)””[“comment_count”] = > となります「0」[「フィルター」] = > と「生」} [“product_type”] = > と「変動」[「価格」] => 以降「12」[“variation_data”] = > array(1) {[「attribute_wtd バリエーション」] = > string(13)「wtd 変動」}} [“line_total”] = > float(12) [“line_tax”] = > int(0) [“line_subtotal”] = > int(12) [“line_subtotal_tax”] = > int(0) [“line_tax_data”] = > array(2) {[「合計」] = > array(0) {} [「小計」] = > array(0) {}}}}

太字テキストから 50 だけを必要です。それは私の製品属性

答え

function mycustom()
{
  global $woocommerce;
  $cart = $woocommerce->cart->get_cart();
    foreach($cart as $key => $value)
    {               
      echo $woocommerce->cart->get_item_data( $value);
    }

}

http://stackoverflow.com/questions/27739868/how-to-get-woocoomerce-product-attribute

スポンサーリンク

Leave a Reply