{"id":61013,"date":"2025-04-26T11:40:14","date_gmt":"2025-04-26T03:40:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/61013\/"},"modified":"2025-04-26T11:40:14","modified_gmt":"2025-04-26T03:40:14","slug":"%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%adzencart%e8%b4%ad%e7%89%a9%e8%bd%a6%e6%98%af%e5%90%a6%e4%b8%ba%e7%a9%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/61013\/","title":{"rendered":"\u5982\u4f55\u5224\u65adzencart\u8d2d\u7269\u8f66\u662f\u5426\u4e3a\u7a7a"},"content":{"rendered":"<p> \u5173\u4e8e\u5982\u4f55\u5224\u65adzencart\u8d2d\u7269\u8f66\u662f\u5426\u4e3a\u7a7a\u7684\u95ee\u9898\uff0c\u5982\u679c\u5bf9shopping_cart\u7c7b\u6bd4\u8f83\u719f\u6089\u7684\u8bdd\uff0c\u90a3\u5c31\u597d\u7406\u89e3\u591a\u4e86\u3002&nbsp;<\/p>\n<p> \u8d2d\u7269\u8f66\u7c7b\u5728includes\\classes\\shopping_cart.php \u6587\u4ef6\u4e2d\uff0c\u6709\u5174\u8da3\u7684\u8bdd\u53ef\u4ee5\u53bb\u770b\u770b\u8fd9\u4e2a\u7c7b\u7684\u65b9\u6cd5\u8bf4\u660e\uff0c\u91cc\u9762\u90fd\u6709\u8be6\u7ec6\u7684\u82f1\u6587\u6ce8\u91ca\u3002\u800c\u5982\u679c\u8981\u5224\u65ad\u5f53\u524d\u7684\u8d2d\u7269\u8f66\u662f\u5426\u4e3a\u7a7a\u7684\u8bdd\uff0c\u53ef\u4ee5\u8c03\u7528\u51fd\u6570&nbsp;<br \/> &nbsp;<br \/> \/**&nbsp;<br \/> &nbsp; &nbsp;* Method to count total number of items in cart \/\/&nbsp;<br \/> &nbsp; &nbsp;*&nbsp;<br \/> &nbsp; &nbsp;* Note this is not just the number of distinct items in the cart,&nbsp;<br \/> &nbsp; &nbsp;* but the number of items adjusted for the quantity of each item&nbsp;<br \/> &nbsp; &nbsp;* in the cart, So we have had 2 items in the cart, one with a quantity&nbsp;<br \/> &nbsp; &nbsp;* of 3 and the other with a quantity of 4 our total number of items&nbsp;<br \/> &nbsp; &nbsp;* would be 7&nbsp;<br \/> &nbsp; &nbsp;*&nbsp;<br \/> &nbsp; &nbsp;* @return total number of items in cart&nbsp;<br \/> &nbsp; &nbsp;*\/&nbsp;<br \/> &nbsp; function count_contents() {&nbsp;<br \/> &nbsp; &nbsp; $this-&gt;notify(&#8216;NOTIFIER_CART_COUNT_CONTENTS_START&#8217;);&nbsp;<br \/> &nbsp; &nbsp; $total_items = 0;&nbsp;<br \/> &nbsp; &nbsp; if (is_array($this-&gt;contents)) {&nbsp;<br \/> &nbsp; &nbsp; &nbsp; reset($this-&gt;contents);&nbsp;<br \/> &nbsp; &nbsp; &nbsp; while (list($products_id, ) = each($this-&gt;contents)) {&nbsp;<br \/> &nbsp; &nbsp; &nbsp; &nbsp; $total_items += $this-&gt;get_quantity($products_id);&nbsp;<br \/> &nbsp; &nbsp; &nbsp; }&nbsp;<br \/> &nbsp; &nbsp; }&nbsp;<br \/> &nbsp; &nbsp; $this-&gt;notify(&#8216;NOTIFIER_CART_COUNT_CONTENTS_END&#8217;);&nbsp;<br \/> &nbsp; &nbsp; return $total_items;&nbsp;<br \/> &nbsp; }&nbsp;<br \/> count_contents() \u8fd9\u4e2a\u51fd\u6570\u5c31\u662f\u83b7\u53d6\u5f53\u524d\u8d2d\u7269\u8f66\u4e2d\u6240\u6709\u5546\u54c1\u7684\u6570\u91cf\uff0c\u540c\u4e00\u79cd\u5546\u54c1\u591a\u4e2a\u6570\u91cf\u4e5f\u90fd\u7b97\u5230\u603b\u6570\u4e2d\u3002\u5982\u679c\u8d2d\u7269\u8f66\u6ca1\u6709\u5546\u54c1\uff0c\u5219\u8be5\u51fd\u6570\u8fd4\u56de0\u4e2a\u5546\u54c1\uff0c\u5426\u5219\u5c31\u4e0d\u662f\u7a7a\u7684\u3002\u6240\u4ee5\u53ef\u4ee5\u8fd9\u6837\u6765\u5224\u65ad\u662f\u5426\u4e3a\u7a7a&nbsp;<\/p>\n<p> if($_SESSION[&#8216;cart&#8217;]-&gt;count_contents() ==0){&nbsp;<br \/> &nbsp; \u8d2d\u7269\u8f66\u4e3a\u7a7a\u7684&nbsp;<br \/> }&nbsp;<\/p>\n<p> \u8c03\u7528\u8d2d\u7269\u8f66\u5bf9\u8c61\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528$_SESSION[&#8216;cart&#8217;]\uff0c\u56e0\u4e3a\u5b83\u4e00\u5f00\u59cb\u5c31\u521d\u59cb\u5316\u4e86\uff0c\u5b58\u653e\u5728\u5f53\u524dsession\u4e2d&nbsp;<br \/> &nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e\u5982\u4f55\u5224\u65adzencart\u8d2d\u7269\u8f66\u662f\u5426\u4e3a\u7a7a\u7684\u95ee\u9898\uff0c\u5982\u679c\u5bf9shopping_cart\u7c7b\u6bd4\u8f83\u719f\u6089\u7684\u8bdd\uff0c\u90a3\u5c31\u597d\u7406\u89e3\u591a\u4e86\u3002&nbsp; \u8d2d\u7269\u8f66\u7c7b\u5728includes\\classes\\shopping_cart.php \u6587\u4ef6\u4e2d\uff0c\u6709\u5174\u8da3\u7684\u8bdd\u53ef\u4ee5\u53bb\u770b\u770b\u8fd9\u4e2a\u7c7b\u7684\u65b9\u6cd5\u8bf4\u660e\uff0c\u91cc\u9762\u90fd\u6709\u8be6\u7ec6\u7684\u82f1\u6587\u6ce8\u91ca\u3002\u800c\u5982\u679c\u8981\u5224\u65ad\u5f53\u524d\u7684\u8d2d\u7269\u8f66\u662f\u5426\u4e3a\u7a7a\u7684\u8bdd\uff0c\u53ef\u4ee5\u8c03\u7528\u51fd\u6570&nbsp; &nbsp; \/**&nbsp; &nbsp; &nbsp;* Method to count total number of items in cart \/\/&nbsp; &nbsp; &nbsp;*&nbsp; &nbsp; &nbsp;* Note this is not just the number of distinct items in the cart,&nbsp; &nbsp; &nbsp;* but the number of items adjusted for the quantity of each item&nbsp; &nbsp; &nbsp;* in the cart, So we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-61013","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=61013"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61013\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=61013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=61013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=61013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}