2017-11-11 71 views

回答

0

這是這樣做的功能。文件storefront/inc/woocommerce/storefront-woocommerce-template-functions.php

if (! function_exists('storefront_cart_link')) { 
    /** 
    * Cart Link 
    * Displayed a link to the cart including the number of items present and the cart total 
    * 
    * @return void 
    * @since 1.0.0 
    */ 
    function storefront_cart_link() { 
     ?> 
      <a class="cart-contents" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php esc_attr_e('View your shopping cart', 'storefront'); ?>"> 
       <span class="amount"><?php echo wp_kses_data(WC()->cart->get_cart_subtotal()); ?></span> <span class="count"><?php echo wp_kses_data(sprintf(_n('%d item', '%d items', WC()->cart->get_cart_contents_count(), 'storefront'), WC()->cart->get_cart_contents_count()));?></span> 
      </a> 
     <?php 
    } 
} 

你需要在你的子主題的functions.php文件來定義功能,或在plugin

希望這會有所幫助。

+0

這不是我的問題的解決方案。我想改變現有的購物車,但我用jQuery不夠好。我找不到負責顯示計數和「項目」的部分代碼。 –

+0

你也可以破解翻譯條目。但這不是一個真正的解決方案。 我認爲如果你在你的'functions.php'中定義了'storefront_cart_link'來滿足你的需要,這將使得它作爲woocommerce做ajax調用並插入返回的html。 這是PHP寫的,我認爲它是在PHP應該做的。 請分享更多的信息,所以我可以建議更好。 – JBoulhous

+0

我認爲我讓自己變得聰明。如果購物車是空的。我希望顯示「0」而不用單詞「item」。如果有一個項目,例如,一個項目。我希望顯示「1」而不用「item」 –

相關問題