ändern Sie Text im Warenkorb Woocommerce WordPress - WordPress, Funktion, woocommerce

Ich habe die WordPress mit Woocommerce verwendet. Ich habe den folgenden Code in functions.php verwendet, um anzuzeigen, wie viele Artikel sich im Warenkorb befinden.

<?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>

Wenn sich kein Produkt im Warenkorb befindet, wird 0items- $ 0 angezeigt. Stattdessen muss ich den Text "Ihr Warenkorb ist leer" anzeigen. Ich bin ein Neuling und weiß nicht, wie ich das mit dieser Funktion erledigen kann.

Antworten:

0 für die Antwort № 1

Sie müssen den Code in der header.php wie folgt ändern:

<?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>