Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] Adding a cart icon with number of items and total cost in nav menu

Home Forums Support Adding a cart icon with number of items and total cost in nav menu

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #465650
    Kobi


    I wanted to know if I could,Adding a cart icon with number of items and total cost in nav menu.

    #465951
    Leo
    Staff
    Customer Support

    Hi there,

    Take a look at this for the quantity: https://generatepress.com/forums/topic/show-quantity-in-cart-in-menu-instead-of-total-costs/

    The cost should be there by default. You can check it out here:
    http://demo.generatepress.com/shop/

    Let me know if this helps.

    #466223
    Kobi

    Thanks. Leo
    I just add this code, its work.
    But the icon did not change, it’s still CART
    After I press CART it does not open a window and shows me the stuff.

    #466262
    Leo
    Staff
    Customer Support
    #466429
    Kobi

    No. I still have the title Rewriting Cart. It does not change it to the icon.
    I want it to look like this site template: https://www.templatemonster.com/demo/60096.html

    When I click on the icon, I open a small window that has the View Cart / Checkout option.
    And it shows me the products I’ve put into the basket

    #466812
    Tom
    Lead Developer
    Lead Developer

    In the code Leo linked to: https://generatepress.com/forums/topic/show-quantity-in-cart-in-menu-instead-of-total-costs/#post-332691

    Find this:

    <?php _e( 'Cart','generate-woocommerce' );?>

    And replace it with this:

    <i class="fa fa-cart"></i>

    #466858
    Kobi

    Hi. Tom Thanks for the replay
    But it still does not look like a website template I put here.
    And I replaced what you told me to change. And still do not have the icon (product basket)

    #466998
    Leo
    Staff
    Customer Support
    #467033
    Kobi

    Thanks Leo
    Yes, I managed to fix it. But I wanted to click on an icon, open a window that could see the products and improve cart / checkout
    As formatted on this site
    https://www.templatemonster.com/demo/60096.html

    #467171
    Tom
    Lead Developer
    Lead Developer

    At this point that would require a custom plugin, although we do have something like that planned in a future version.

    I believe one of our users created a custom plugin to achieve this sort of layout (without any styling). If you join our Facebook group (GeneratePress Community) and ask about it, someone might be able to point you to that plugin.

    #467605
    Kobi

    Thanks Tom
    I think I’ll stick with the code you gave me here.
    But my problem with this code, which I can not seem to translate into my language.
    (View your shopping cart) this title to my language

    #467770
    Tom
    Lead Developer
    Lead Developer

    That text is on the line above where you switched out the cart text for the icon – you should be able to edit it directly.

    #467863
    Kobi

    I changed the title, but he does not recognize my language (Hebrew)
    He shows me icons of question marks
    https://s10.postimg.org/k9frwme15/image.jpg

    #468159
    Tom
    Lead Developer
    Lead Developer

    Can I see your code? Paste it into the editor, highlight it and then click the “code” button in the editor toolbox 🙂

    #468174
    Kobi
    <?php
    /**
     * GeneratePress.
     *
     * Please do not make any edits to this file. All edits should be done in a child theme.
     *
     * @package GeneratePress
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    
    // Set our theme version.
    define( 'GENERATE_VERSION', '2.0.1' );
    
    if ( ! function_exists( 'generate_setup' ) ) {
    	add_action( 'after_setup_theme', 'generate_setup' );
    	/**
    	 * Sets up theme defaults and registers support for various WordPress features.
    	 *
    	 * @since 0.1
    	 */
    	function generate_setup() {
    		// Make theme available for translation.
    		load_theme_textdomain( 'generatepress' );
    
    		// Add theme support for various features.
    		add_theme_support( 'automatic-feed-links' );
    		add_theme_support( 'post-thumbnails' );
    		add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'status' ) );
    		add_theme_support( 'woocommerce' );
    		add_theme_support( 'title-tag' );
    		add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) );
    		add_theme_support( 'customize-selective-refresh-widgets' );
    
    		add_theme_support( 'custom-logo', array(
    			'height' => 70,
    			'width' => 350,
    			'flex-height' => true,
    			'flex-width' => true
    		) );
    
    		// Register primary menu.
    		register_nav_menus( array(
    			'primary' => __( 'Primary Menu', 'generatepress' ),
    		) );
    
    		/**
    		 * Set the content width to something large
    		 * We set a more accurate width in generate_smart_content_width()
    		 */
    		global $content_width;
    		if ( ! isset( $content_width ) ) {
    			$content_width = 1200; /* pixels */
    		}
    
    		// This theme styles the visual editor to resemble the theme style.
    		add_editor_style( 'css/admin/editor-style.css' );
    	}
    }
    
    /**
     * Get all necessary theme files
     */
    require get_template_directory() . '/inc/theme-functions.php';
    require get_template_directory() . '/inc/defaults.php';
    require get_template_directory() . '/inc/class-css.php';
    require get_template_directory() . '/inc/css-output.php';
    require get_template_directory() . '/inc/general.php';
    require get_template_directory() . '/inc/customizer.php';
    require get_template_directory() . '/inc/markup.php';
    require get_template_directory() . '/inc/element-classes.php';
    require get_template_directory() . '/inc/typography.php';
    require get_template_directory() . '/inc/plugin-compat.php';
    require get_template_directory() . '/inc/migrate.php';
    require get_template_directory() . '/inc/deprecated.php';
    
    if ( is_admin() ) {
    	require get_template_directory() . '/inc/meta-box.php';
    	require get_template_directory() . '/inc/dashboard.php';
    }
    
    /**
     * Load our theme structure
     */
    require get_template_directory() . '/inc/structure/archives.php';
    require get_template_directory() . '/inc/structure/comments.php';
    require get_template_directory() . '/inc/structure/featured-images.php';
    require get_template_directory() . '/inc/structure/footer.php';
    require get_template_directory() . '/inc/structure/header.php';
    require get_template_directory() . '/inc/structure/navigation.php';
    require get_template_directory() . '/inc/structure/post-meta.php';
    require get_template_directory() . '/inc/structure/sidebars.php';
    
    function custom_wc_cart_link() {
        ob_start();
        ?>
        <a href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" class="cart-contents" title="עגלה שלי"<?php esc_attr_e( 'View your shopping cart','generate-woocommerce' ); ?>">
            <i class="fa fa-shopping-cart"  aria-hidden="true"></i> <small><?php echo sprintf ( _n( '%d', '%d', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?></small>
        </a>
        <?php
        return ob_get_clean();
    }
    
    function custom_wc_menu_cart( $nav, $args ) {
        if ( $args->theme_location == 'primary' && generatepress_wc_get_setting( 'cart_menu_item' ) ) {
            return sprintf( 
                '%1$s 
                <li class="wc-menu-item %4$s" title="%2$s">
                    %3$s
                </li>',
                $nav,
                esc_attr__( 'View your shopping cart','generate-woocommerce' ),
                custom_wc_cart_link(),
                is_cart() ? 'current-menu-item' : ''
            );
        }
    	
        // Our primary menu isn't set, return the regular nav
        return $nav;
    }
    
    add_action( 'after_setup_theme','remove_wc_cart_item' );
    function remove_wc_cart_item() {
        remove_filter( 'wp_nav_menu_items','generatepress_wc_menu_cart', 10, 2 );
        add_filter( 'wp_nav_menu_items','custom_wc_menu_cart', 10, 2 );
        add_filter( 'woocommerce_add_to_cart_fragments', 'custom_wc_cart_link' );
    
    }
Viewing 15 posts - 1 through 15 (of 22 total)
  • You must be logged in to reply to this topic.