我需要一些帮助。我试图抓住applied_coupons公共类的值,我不能为我的生活让它在apply_coupons的公共类中显示数组的值。我根本不是OOP世界的大师,我老实说也输了。
转储:
var_dump($woocommerce);
object(Woocommerce)[357]
public 'version' => string '2.0.14' (length=6)
public 'plugin_url' => string 'url here' (length=57)
public 'plugin_path' => string 'path here' (length=52)
public 'template_url' => string 'template here' (length=12)
public 'errors' =>
array
empty
public 'messages' =>
array
empty
public 'query' =>
object(WC_Query)[266]
public 'unfiltered_product_ids' =>
array
empty
public 'filtered_product_ids' =>
array
empty
public 'post__in' =>
array
empty
public 'meta_query' => string '' (length=0)
public 'layered_nav_post__in' =>
array
empty
public 'layered_nav_product_ids' =>
array
empty`enter code here`
public 'product_factory' =>
object(WC_Product_Factory)[254]
public 'cart' =>
object(WC_Cart)[263]
public 'cart_contents' =>
array
'35f4a8d465e6e1edc05f3d8ab658c551' =>
array
...
public 'applied_coupons' =>
array
0 => string 'free249' (length=7)
我需要什么:
applied_coupons类的值(free249)
我尝试了什么:
(Returns Null)
$coupon_code_found = $woocommerce->applied_coupons[0];
var_dump($coupon_code_found);
(Returns boolean false)
$coupon_code_found = $woocommerce->applied_coupons;
var_dump($coupon_code_found);
(Returns Null)
$coupon_code_found = $woocommerce->$cart->$WC_Cart->applied_coupons[0];
var_dump($coupon_code_found);
答案 0 :(得分:2)
$woocommerce->cart->applied_coupons;
应该返回你需要的东西。
当您键入$woocommerce->$cart
时,PHP会尝试将$cart
替换为$cart
变量的值,在这种情况下该变量不正确。通过跳过$
,您告诉PHP您希望从给定对象获取该名称的变量。