在页面上显示woocommerce购物车项目

时间:2013-07-08 01:30:00

标签: woocommerce cart

我正在使用wordpress中的woocommerce ..我无法让它显示购物车项目名称和购物车项目的成本。加上wordpress页面上的总数..任何人都可以帮助我吗?

woocommerce的钩子在这里:http://docs.woothemes.com/document/hooks/

我尝试的代码是:

<?php

/*
Display number of items in cart and total
*/

global $woocommerce;

echo "Items in cart: ".sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);
echo "<br />";
echo "Total: ".$woocommerce->cart->get_cart_total();

?>

1 个答案:

答案 0 :(得分:2)

试试这个:

global $woocommerce;
$cart = $woocommerce->cart->cart_contents;
foreach($cart as $item){
   $name = $item['data']->parent->post->post_title;
   $price = $item['line_total'] / $item['quantity'];
}