Avinash Gupta Avinash Gupta - 8 months ago 55
PHP Question

Get product value on cart

Array
(
[1a0421df7401f1b79616141d5a4e223a] => Array
(
[rental_data] => Array
(
[pickup_date] => 2017/10/02
[dropoff_date] => 2017/10/05
[rental_days_and_costs] => Array
(
[days] => 3
[hours] => 0
[booked_dates] => Array
(
[formatted] => Array
(
[0] => 2017/10/02
[1] => 2017/10/03
[2] => 2017/10/04
)

[iso] => Array
(
[0] => 1506902400
[1] => 1506988800
[2] => 1507075200
)

)

[cost] => 123.75
[due_payment] => 251.25
)

[max_hours_late] => 0
)

[product_id] => 181
[variation_id] => 0
[variation] => Array
(
)

[quantity] => 1
[line_total] => 123.75
[line_subtotal] => 123.75
[line_tax] => 0
[line_subtotal_tax] => 0
[line_tax_data] => Array
(
[total] => Array
(
)

[subtotal] => Array
(
)

)

[data] => WC_Product_Redq_Rental Object
(
[object_type:protected] => product
[post_type:protected] => product
[cache_group:protected] => products
[data:protected] => Array
(
[name] => Spelga House (sleeps 10)
[slug] => spelga-house-accomodation
[date_created] => WC_DateTime Object
(
[utc_offset:protected] => 0
[date] => 2016-02-06 10:36:40.000000
[timezone_type] => 3
[timezone] => Europe/London
)

[date_modified] => WC_DateTime Object
(
[utc_offset:protected] => 0
[date] => 2017-09-25 13:06:09.000000
[timezone_type] => 3
[timezone] => Europe/London
)

[status] => publish
[featured] =>
[catalog_visibility] => visible
[description] => A large detached, recently renovated high spec modern house, previously owned by the water board and maintains its characteristics. Spelga House has spectacular views of the surrounding Mourne Mountains, and only seven miles from the lively resort town of Newcastle and three miles from Hilltown. The house sits in front of the dam wall, on top of the Mournes, and is


i want to get the value of
[due_payment]
array in woocommerce cart page and
[1a0421df7401f1b79616141d5a4e223a]
root name change each time for each product how i get this any help? I am using the rental and booking woocommerce plugin and product type is rental product in woocommerce I am beginners for the array and plugin customozation I also search for that but i didn,t get any idea how i get the value of
[due_payment]
array . please guide me how i do that

Answer Source

You need to apply one more foreach() like below:-

global $woocommerce; 
$items = $woocommerce->cart->get_cart();    
foreach($items as $item => $values) {  
    foreach($values as $arr){ //apply one-more foreach()
      echo $arr['rental_data']['rental_days_and_costs']['due_payment'];‌​‌
    }
}

Note:- You can curtale thses two lines:-

global $woocommerce; 
$items = $woocommerce->cart->get_cart();

Into one:-

$items = WC()->cart->get_cart(); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download