Don*_*ite 2 php wordpress function
我有一个像 $cart_item_key = f7ebf06b2c9ff23e2efe046992eb949c
默认情况下,此键有一个数组 ( WC->cart->get_cart()
)
Array ( [f7ebf06b2c9ff23e2efe046992eb949c] =>
Array ( [unique_key] => 6bf1cd893cfb6ea388076bc99a08891a
[thwepof_options] =>
Array ( [order_date] =>
Array ( [name] => order_date
[value] => 06-02-2018, monday
[label] => Order date [options] => ) )
[key] => f7ebf06b2c9ff23e2efe046992eb949c
[product_id] => 770
[variation_id] => 771
[variation] => Array ( )
[quantity] => 1
) ) )
Run Code Online (Sandbox Code Playgroud)
我没有在WooCommerce 文档中找到任何可以帮助我解决此问题的功能。
最初这就是 Woocommerce 调用购物车项目的方式,但我过滤了未来开发所需的那些键:
foreach( WC()->cart->get_cart() as $cart_item ) {
Run Code Online (Sandbox Code Playgroud)
我在论坛上找到了这个解决方案,但这些都没有奏效。
小智 5
There is a method in cart object call get_cart_item( $item_key )
, if you pass the $cart_item_key
as method argument you'll get the item data. For more details check the source https://docs.woocommerce.com/wc-apidocs/source-class-WC_Cart.html#615-623
WC()->cart->get_cart_item( $cart_item_key );
Run Code Online (Sandbox Code Playgroud)