top of page

Update Cart Qty in Site header via WooCommerce

  • Writer: سُلَيْمَان بْن دَاوُوْد
    سُلَيْمَان بْن دَاوُوْد
  • Dec 24, 2021
  • 1 min read

Custom Code to be places in plugin code file



add_filter( 'woocommerce_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-customlocation" href="<?php echo site_url('cart'); ?>">
        <span><?php echo $woocommerce->cart->cart_contents_count; ?></span>
        <i class="fa fa-shopping-cart"></i>
    </a>
    <?php
    $fragments['a.cart-customlocation'] = ob_get_clean();
    return $fragments;
}


<div class="right-menus-list">
	<?php global $woocommerce; ?>
	<ul>
		<li class="shopping-cart">
			<a class="cart-customlocation" href="<?php echo $woocommerce->cart->get_cart_url(); ?>">
				<span><?php echo $qty = $woocommerce->cart->get_cart_contents_count(); ?></span><i class="fa fa-shopping-cart"></i></a></li>
		<li>
			<?php
				$args2 = array( 'menu'=> 'HeaderSideMenu', 'container'=>'');

				wp_nav_menu($args2)
			?>
		</li>
	</ul>

</div>


 
 
 

Recent Posts

See All
Duplicate Category in Wordpress

The following code helps to duplicate the default wordpress category by help of code. // Add Duplicate option for categories in WordPress...

 
 
 
C#.NET and Its Associated Codes

1- Creating an Desktop Application in C#.NET C# ADO.NET & MySQL MAIN C# and MySQL ADO.NET with Crystals Reports Ready Code 2- Handling...

 
 
 

Comments


© 2020 by syednazrulhassan

bottom of page