2016-08-22 54 views
-2

我有這樣的陣列,即從WooCommerce使用這些線路甩:WooCommerce預訂 - 檢索購物車中的特定數據?

$items = $woocommerce->cart->get_cart(); 
foreach($items as $item => $values) { 
    // some code here… 
} 

如果我讓我的車的原始輸出($項目),我得到這個:

array(1) { 
    ["f584d8671586d336d84e8cf9ed43303c"]=> 

    array(11) { 


["booking"]=> 
array(15) { 
    ["_year"]=> 
    int(2016) 
    ["_month"]=> 
    int(8) 
    ["_day"]=> 
    int(28) 
    ["_persons"]=> 
    array(1) { 
    [0]=> 
    int(1) 
    } 
    ["_date"]=> 
    string(9) "2016-8-28" 
    ["date"]=> 
    string(13) "28 août 2016" 
    ["_time"]=> 
    string(5) "21:30" 
    ["time"]=> 
    string(11) "21 h 30 min" 
    ["_qty"]=> 
    int(1) 
    ["Personnes"]=> 
    int(1) 
    ["_start_date"]=> 
    int(1472419800) 
    ["_end_date"]=> 
    int(1472421600) 
    ["_all_day"]=> 
    int(0) 
    ["_cost"]=> 
    int(0) 
    ["_booking_id"]=> 
    int(13013) 
} 



["product_id"]=> 
int(12856) 
["variation_id"]=> 
int(0) 
["variation"]=> 
array(0) { 
} 
["quantity"]=> 
int(1) 
["line_total"]=> 
float(0) 
["line_tax"]=> 
int(0) 
["line_subtotal"]=> 
int(0) 
["line_subtotal_tax"]=> 
int(0) 
["line_tax_data"]=> 
array(2) { 
    ["total"]=> 
    array(0) { 
    } 
    ["subtotal"]=> 
    array(0) { 
    } 
} 
["data"]=> 
object(WC_Product_Booking)#11131 (20) { 
    ["availability_rules":"WC_Product_Booking":private]=> 
    array(0) { 
    } 
    ["id"]=> 
    int(12856) 
    ["post"]=> 
    object(WP_Post)#11132 (24) { 
    ["ID"]=> 
    int(12856) 
    ["post_author"]=> 
    string(2) "14" 
    ["post_date"]=> 
    string(19) "2016-08-16 22:04:09" 
    ["post_date_gmt"]=> 
    string(19) "2016-08-16 20:04:09" 
    ["post_content"]=> 
    string(0) "" 
    ["post_title"]=> 
    string(10) "La Cuchara" 
    ["post_excerpt"]=> 
    string(0) "" 
    ["post_status"]=> 
    string(7) "publish" 
    ["comment_status"]=> 
    string(4) "open" 
    ["ping_status"]=> 
    string(6) "closed" 
    ["post_password"]=> 
    string(0) "" 
    ["post_name"]=> 
    string(12) "la-cuchara-2" 
    ["to_ping"]=> 
    string(0) "" 
    ["pinged"]=> 
    string(0) "" 
    ["post_modified"]=> 
    string(19) "2016-08-16 22:13:52" 
    ["post_modified_gmt"]=> 
    string(19) "2016-08-16 20:13:52" 
    ["post_content_filtered"]=> 
    string(0) "" 
    ["post_parent"]=> 
    int(0) 
    ["guid"]=> 
    string(59) "" 
    ["menu_order"]=> 
    int(0) 
    ["post_type"]=> 
    string(7) "product" 
    ["post_mime_type"]=> 
    string(0) "" 
    ["comment_count"]=> 
    string(1) "0" 
    ["filter"]=> 
    string(3) "raw" 
    } 
    ["product_type"]=> 
    string(7) "booking" 
    ["shipping_class":protected]=> 
    string(0) "" 
    ["shipping_class_id":protected]=> 
    int(0) 
    ["total_stock"]=> 
    NULL 
    ["supports":protected]=> 
    array(0) { 
    } 
    ["price"]=> 
    string(1) "0" 
    ["wc_display_cost"]=> 
    string(0) "" 
    ["wc_booking_base_cost"]=> 
    string(0) "" 
    ["wc_booking_min_duration"]=> 
    string(1) "1" 
    ["wc_booking_cost"]=> 
    string(0) "" 
    ["wc_booking_has_resources"]=> 
    string(2) "no" 
    ["wc_booking_has_persons"]=> 
    string(3) "yes" 
    ["wc_booking_has_person_types"]=> 
    string(2) "no" 
    ["wc_booking_min_persons_group"]=> 
    string(1) "1" 
    ["tax_status"]=> 
    string(7) "taxable" 
    ["stock_status"]=> 
    string(7) "instock" 
    ["manage_stock"]=> 
    string(2) "no" 
    } 
    } 
} 

我想在PHP中使用變量特定數據值(預訂日期,時間和人)

["date"]=> string(13) "28 août 2016" 

    ["_persons"]=> array(1) { [0]=> int(1) } 

    ["time"]=> string(11) "21 h 30 min" 

哪有我確實從WooCommerce購物車對象中獲取這些特定值?

感謝

+1

請說明您的具體問題,或添加additio最後的細節,以確切地突出你所需要的。正如目前所寫,很難確切地說出你在問什麼。請參閱[如何提問](http://stackoverflow.com/help/how-to-ask)頁面以獲得澄清此問題的幫助。 –

+0

你好夏洛特, 我有這個數組我想從預約日期鑰匙得到日期28août2016,並把它放到變量中,以在另一個功能中使用它...我沒有打印出來。 – Zufy

+0

請注意,[緊急乞討是堅決不鼓勵](http://meta.stackoverflow.com/q/326569/472495)。 – halfer

回答

3

你可以先嚐試這個(但我因爲我認爲它可以是一個對象不確定,所以可能是它不會工作):

echo $items[0]['booking']['date'] . '<br>'; 
echo $items[0]['booking']['_persons'] . '<br>'; 
echo $items[0]['booking']['time'] . '<br>'; 

如果不是在foreach工作循環將:

$items = WC()->cart->get_cart(); 

foreach($items as $item) { 
    $date = $item['booking']['date']; 
    $person = $item['booking']['_persons']; 
    $time = $item['booking']['time']; 
} 
// displaying values for test 
echo 'Booking - Date: ' . $date . '/ Person: ' . $person . '/ Time: ' . $time; 

其中的一個會的工作,肯定...

+0

謝謝,,工程:) 怎麼樣 [ 「wc_booking_has_resources」] => 字符串(2) 「無」 – Zufy

+0

完成,非常感謝你 – Zufy

+0

非常歡迎您,感謝你解決了一個問題,我花了很多時間:) 從同一陣列我需要這兩個元素[「wc_booking_has_resources」] =>字符串(2)「否」 [「_booking_id」] => int(13013) 返回的值應該是no和13013 在此先感謝先生 – Zufy

相關問題