2013-12-16 42 views
0

我已經使用wordpress與woocommerce。我在functions.php中使用了以下代碼來顯示購物車中有多少物品。更改購物車中的文本woocommerce wordpress

<?php 
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment'); 

function woocommerce_header_add_to_cart_fragment($fragments) { 
global $woocommerce; 
ob_start(); 
?> 
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a> 
<?php 

$fragments['a.cart-contents'] = ob_get_clean(); 

return $fragments; 


} 
?> 

的header.php:

<?php global $woocommerce;?> 
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"> 
<?php 
echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a> 

如果在車中沒有產品就說明0items- $ 0相反,我需要顯示文字「你的籃子是空的」。我是一個新手,不知道如何使用該功能來做到這一點。任何幫助?

回答

0

您需要更改的header.php到下面的代碼,

<?php global $woocommerce;?> 
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"> 
<?php 
if($woocommerce->cart->cart_contents_count == 0){ 
    echo _e("Your Basket is Empty."); 
} 
else{ 
    echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); 
} ?></a> 
相關問題