WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
how to add cart icon in head (4 posts)

  1. icevincent
    Member
    Posted 8 months ago #

    Hello,guys
    I custom a shop theme by woocommerce plugin, now I don't know to how add a cart icon in head ,it could display the count and price of products in the cart at mount

    I download 2 woocommerce shop themes:artificer & wootique form woo's website, they all have cart icon in the head (also have checkout button beside it), but I couldn't find how could they get it in the header.php. There is nothing info about it.

    Can anybody help me?
    Thank you very much!

    Vincent

    http://wordpress.org/plugins/woocommerce/

  2. lemu
    Member
    Posted 8 months ago #

    You could do something like this in your header.php file:

    <?php
    global $woocommerce;
    
    // get cart quantity
    $qty = $woocommerce->cart->get_cart_contents_count();
    
    // get cart total
    $total = $woocommerce->cart->get_cart_total();
    
    // get cart url
    $cart_url = $woocommerce->cart->get_cart_url();
    
    // if multiple products in cart
    if($qty>1)
          echo '<a href="'.$cart_url.'">'.$qty.' products | '.$total.'</a>';
    
    // if single product in cart
    if($qty==1)
          echo '<a href="'.$cart_url.'">1 product | '.$total.'</a>';
    
    ?>

    Adding the cart icon should be relatively easy then. Other cart methods can be found here: http://docs.woothemes.com/wc-apidocs/class-WC_Cart.html

  3. icevincent
    Member
    Posted 8 months ago #

    lemu,
    Thank you very much, the code is great!

  4. bawa0009
    Member
    Posted 21 hours ago #

    hello sir i have used zebra themes in this theme only display the count and price of products but I don't know to how add a cart icon in head

Reply

You must log in to post.

About this Plugin

About this Topic