Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在购物车上获取产品价值_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 在购物车上获取产品价值

Php 在购物车上获取产品价值,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想在woocommerce购物车页面中获取[due_payment]数组的值和[1a0421df7401f1b79616141d5a4e223a]每次更改每个产品的根名称如何获得此帮助?我正在使用租赁和预订woocommerce插件,产品类型是woocommerce中的租赁产品我是阵列和插件定制的初学者,我也在搜索,但我不知道如何获得[due_payment]阵列的价值。请指导我如何做到这一点您需要再申请一个foreach,如下所示:- Array ( [1a0421df7401f1b

我想在woocommerce购物车页面中获取[due_payment]数组的值和[1a0421df7401f1b79616141d5a4e223a]每次更改每个产品的根名称如何获得此帮助?我正在使用租赁和预订woocommerce插件,产品类型是woocommerce中的租赁产品我是阵列和插件定制的初学者,我也在搜索,但我不知道如何获得[due_payment]阵列的价值。请指导我如何做到这一点

您需要再申请一个foreach,如下所示:-

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 
注意:-您可以缩短这两条线:-

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'];‌​‌
    }
}
合二为一:-

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

这里有另一种方法,使用数组键。不需要2个foreach循环

$items = WC()->cart->get_cart(); 
$cart_items = WC()->cart->get_cart(); 
foreach( $cart_items as $cart_item_key => $cart_item ) {  
      echo $cart_items[$cart_item_key]['rental_data']['rental_days_and_costs']['due_payment'];‌​‌
}
还有另一种方法。这次没有foreach循环

$items = WC()->cart->get_cart(); 
$cart_items = WC()->cart->get_cart(); 
foreach( $cart_items as $cart_item_key => $cart_item ) {  
      echo $cart_items[$cart_item_key]['rental_data']['rental_days_and_costs']['due_payment'];‌​‌
}

那就使用foreach吧。在我使用foreach的地方,请指导meglobal$woocommerce$items=$woocommerce->cart->get\u cart;foreach$items as$item=>$values{?>我使用这样的方法来获取数组foreach$values as$arr{echo$arr['rental_data']['rental_days_and_costs']['due_payment'];}
$cart_items = WC()->cart->get_cart();
if ( is_array( $cart_items ) && !empty( $cart_items ) ) {
    $cart_item_keys = array_keys($cart_items);
    echo $cart_items[$cart_item_keys[0]]['rental_data']['rental_days_and_costs']['due_payment'];‌​‌
}