Skip to content

Instantly share code, notes, and snippets.

@alexpani
Last active October 30, 2016 18:44
Show Gist options
  • Save alexpani/5220510 to your computer and use it in GitHub Desktop.
Save alexpani/5220510 to your computer and use it in GitHub Desktop.
Woocommerce Mini Cart
<?php
/** Show item number on cart **/
/* Uso: <?php minicart(); ?> */
/* Plugin consigliato: WP PHP widget */
function minicart( $echo = true ) {
global $woocommerce;
ob_start();
// quantity
$qty = 0;
if (sizeof($woocommerce->cart->get_cart())>0) : foreach ($woocommerce->cart->get_cart() as $item_id => $values) :
$qty += $values['quantity'];
endforeach; endif;
if ( $qty == 1 )
$label = __( 'Articolo nel carrello', 'yiw' );
else
$label = __( 'Articoli nel carrello', 'yiw' ); ?>
<div id="minicart">
<a class="widget_shopping_cart trigger " href="<?php echo $woocommerce->cart->get_cart_url() ?>">
<div><span class="minicart"><?php echo $qty ?> <?php echo $label ?> </span></div>
</a></div>
<?php
$html = ob_get_clean();
if ( $echo )
echo $html;
else
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment