Woocommerce Custom Payment Gateway Example Codes

https://www.dropbox.com/sh/uv5y7q6ryazm9zj/AAA-MgA6Neompydue1LNSsjka?dl=0

Advertisements

Woocommerce – Display shopping cart details on a WordPress menu

Open your theme’s functions.php.

Add below code:

add_filter('wp_nav_menu_items','wc_custom_menu_cart', 10, 2);
function wc_custom_menu_cart($menu, $args) {

 // Check if WooCommerce is active and add a new item to a menu assigned to Primary Navigation Menu location
 if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || 'primary' !== $args->theme_location )
 return $menu;

 $cart_url = WC()->cart->get_cart_url();
 $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
 $viewing_cart = __('View your shopping cart', 'exploore');
 $start_shopping = __('Start shopping', 'exploore');
 $count = (int) WC()->cart->cart_contents_count;
 $cart_contents = sprintf(_n('%d item', '%d items', $count, 'exploore'), $count);
 $cart_total = WC()->cart->get_cart_total();
 
 $menu_item = '<li>';
 if ( $count > 0 ) { 
 $menu_item.= '<a class="cart-contents" href="'. $cart_url .'" title="'. $viewing_cart .'">';
 } else {
 $menu_item.= '<a class="cart-contents" href="'. $shop_page_url .'" title="'. $start_shopping .'">';
 }
 $menu_item.= '<i class="fa fa-shopping-cart"></i> ';
 $menu_item.= $cart_contents.' - '. $cart_total;
 $menu_item.= '</a>';
 $menu_item.= '</li>';

 $menu.=$menu_item;

 return $menu;
}

function my_header_add_to_cart_fragment( $fragments ) {
 
 ob_start();
 $cart_url = WC()->cart->get_cart_url();
 $shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
 $viewing_cart = __('View your shopping cart', 'exploore');
 $start_shopping = __('Start shopping', 'exploore');
 $count = WC()->cart->cart_contents_count;
 $cart_contents = sprintf(_n('%d item', '%d items', $count, 'exploore'), $count);
 $cart_total = WC()->cart->get_cart_total();

 if ( $count == 0 ) {
 ?>
 <a class="cart-contents" href="<?php echo $shop_page_url;?>" title="<?php echo $start_shopping;?>"><i class="fa fa-shopping-cart"></i> <?php echo $cart_contents.' - '. $cart_total;?></a>
 <?php } else { ?>
 <a class="cart-contents" href="<?php echo $cart_url;?>" title="<?php echo $viewing_cart;?>"><i class="fa fa-shopping-cart"></i> <?php echo $cart_contents.' - '. $cart_total;?></a>
 <?php
 }
 $fragments['a.cart-contents'] = ob_get_clean();
 
 return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'my_header_add_to_cart_fragment' );