【问题标题】:Displaying woocommerce cart items on a page在页面上显示 woocommerce 购物车项目
【发布时间】:2013-07-05 06:40:32
【问题描述】:

我在 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();

?>

【问题讨论】:

    标签: woocommerce cart


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-13
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2020-05-09
      • 1970-01-01
      相关资源
      最近更新 更多