{"id":1768,"date":"2020-12-20T00:34:32","date_gmt":"2020-12-20T00:34:32","guid":{"rendered":"https:\/\/docs.generatepress.com\/?post_type=keep_articles&p=1768"},"modified":"2020-12-23T04:48:19","modified_gmt":"2020-12-23T04:48:19","slug":"move-woocommerce-cart-toggle-into-the-menu-items","status":"publish","type":"keep_articles","link":"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/","title":{"rendered":"Move WooCommerce Cart Toggle Into the Menu Items"},"content":{"rendered":"\n

By default, the WooCommerce cart icon<\/a> is separated from the main menu like this:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

If you prefer move the icon as part of the menu items like this:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

Then try the following PHP<\/a> snippet:<\/p>\n\n\n\n

add_filter( 'wp_nav_menu_items', function( $items, $args ) {\n    if ( 'primary' === $args->theme_location ) {\n        $has_items = false;\n\n        if ( ! WC()->cart->is_empty() ) {\n            $has_items = 'has-items';\n        }\n\n        return sprintf(\n            '%1$s\n            <li class=\"wc-menu-item menu-item-align-right %3$s %4$s\">\n                %2$s\n            <\/li>',\n            $items,\n            generatepress_wc_cart_link(),\n            is_cart() ? 'current-menu-item' : '',\n            $has_items\n        );\n    }\n\n    return $items;\n}, 10, 2 );<\/code><\/pre>\n","protected":false},"template":"","yoast_head":"\nMove WooCommerce Cart Toggle Into the Menu Items - Documentation<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Move WooCommerce Cart Toggle Into the Menu Items - Documentation\" \/>\n<meta property=\"og:description\" content=\"By default, the WooCommerce cart icon is separated from the main menu like this: If you prefer move the icon as part of the menu items like this: Then try the following PHP snippet:\" \/>\n<meta property=\"og:url\" content=\"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/\" \/>\n<meta property=\"og:site_name\" content=\"Documentation\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GeneratePress\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-23T04:48:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/docs.generatepress.com\/wp-content\/uploads\/2020\/12\/woocommerce_cart.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@GeneratePress\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/\",\"url\":\"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/\",\"name\":\"Move WooCommerce Cart Toggle Into the Menu Items - Documentation\",\"isPartOf\":{\"@id\":\"https:\/\/docs.generatepress.com\/#website\"},\"datePublished\":\"2020-12-20T00:34:32+00:00\",\"dateModified\":\"2020-12-23T04:48:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/docs.generatepress.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\/\/docs.generatepress.com\/article\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Move WooCommerce Cart Toggle Into the Menu Items\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/docs.generatepress.com\/#website\",\"url\":\"https:\/\/docs.generatepress.com\/\",\"name\":\"Documentation\",\"description\":\"Get to Know GeneratePress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/docs.generatepress.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Move WooCommerce Cart Toggle Into the Menu Items - Documentation","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/","og_locale":"en_US","og_type":"article","og_title":"Move WooCommerce Cart Toggle Into the Menu Items - Documentation","og_description":"By default, the WooCommerce cart icon is separated from the main menu like this: If you prefer move the icon as part of the menu items like this: Then try the following PHP snippet:","og_url":"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/","og_site_name":"Documentation","article_publisher":"https:\/\/www.facebook.com\/GeneratePress","article_modified_time":"2020-12-23T04:48:19+00:00","og_image":[{"url":"https:\/\/docs.generatepress.com\/wp-content\/uploads\/2020\/12\/woocommerce_cart.png"}],"twitter_card":"summary_large_image","twitter_site":"@GeneratePress","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/","url":"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/","name":"Move WooCommerce Cart Toggle Into the Menu Items - Documentation","isPartOf":{"@id":"https:\/\/docs.generatepress.com\/#website"},"datePublished":"2020-12-20T00:34:32+00:00","dateModified":"2020-12-23T04:48:19+00:00","breadcrumb":{"@id":"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/docs.generatepress.com\/article\/move-woocommerce-cart-toggle-into-the-menu-items\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/docs.generatepress.com\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/docs.generatepress.com\/article\/"},{"@type":"ListItem","position":3,"name":"Move WooCommerce Cart Toggle Into the Menu Items"}]},{"@type":"WebSite","@id":"https:\/\/docs.generatepress.com\/#website","url":"https:\/\/docs.generatepress.com\/","name":"Documentation","description":"Get to Know GeneratePress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/docs.generatepress.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/keep-api\/1768"}],"collection":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/keep-api"}],"about":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/types\/keep_articles"}],"wp:attachment":[{"href":"https:\/\/docs.generatepress.com\/wp-json\/wp\/v2\/media?parent=1768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}