Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • im a total loser with coding > php

    but maybe what we want could be done like this:

    1- create a widget area

    2- position widget area into theme > heading

    3- insert data inside the widget area. the data = load woocommerce variables and echo it.

    —-

    1 to 2 = https://www.themesandco.com/snippet/add-widget-area-header/

    3 = we should find a way to know how to: add content into a widget area (with ‘id’ => ‘customname’ ) using functions hooks.

    and in that function we could add woocommerce variables

    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 id="cart_in_menu_11" class="cart_is_in_menu" href="'.$cart_url.'">'.$qty.' products | '.$total.'</a>';
    
    	// if single product in cart
    	if($qty==1)
    	      echo '<a id="cart_in_menu_1" class="cart_is_in_menu"  href="'.$cart_url.'">1 product | '.$total.'</a>';

    yavarkhan

    you want the cart to go into a extra.widget area. that is located in the header?

    // addd cat in header
    
    add_filter('wp_nav_menu_items','add_cart_in_menu', 10, 2);
    
    function add_cart_in_menu( $menu, $args ) {
    
        if( $args->theme_location == 'primary')  {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 class="cart_is_in_menu" href="'.$cart_url.'">'.$qty.' products | '.$total.'</a>';
    
    	// if single product in cart
    	if($qty==1)
    	      echo '<a class="cart_is_in_menu"  href="'.$cart_url.'">1 product | '.$total.'</a>';
    
        }
        return $menu;
    
    }

    is this bit of code correct?

    hey guys ??

    have a question.

    how can i add those cart info inside the Heading in unique div?. in a way that its not inside the nav.ul.li
    like
    <heading>
    <brand> <nav.ul.li> <cart>
    </heading>

Viewing 4 replies - 1 through 4 (of 4 total)