/*
* Get a cart product/item's variation as a key=>value pair
*/
function store_get_cart_product_variations($cart_item) {
$variations = WC()->cart->get_item_data($cart_item, true);
// Explode and trim
$parts = explode(PHP_EOL, $variations);
$parts = array_filter($parts);
// Build a key=>value pair, trim any extra whitespace
$variations = array();
foreach($parts as $part) {
list($key, $value) = explode(':', $part);
$variations[trim($key)] = trim($value);
}
return $variations;
}
1条答案
按热度按时间oxiaedzo1#
这个函数接受一个购物车项目,并返回一个key=〉value数组。
将其放置在
functions.php
中然后它可以这样使用: