Cart menu icon
Is there anyway to add cart iconto menu and display the quantity?
Yes the same feature I am also looking for dynamic cart with product car count in it in the menu. Is that possible please this is most basic feature in all e-commerce plugin and we are expecting the same in fluentcart too.
Suffian Ahmed I didn't find any method to do that.
Ming Xu may be the fluentcart ninja team will help with this as addon feature in the upcoming release. I too didn't find any third party plugin or short code for cart count icon in header menu. Please We are support from the team, and Expect this is necessary basic and useful feature for all e-commerce plugins out there and highly important +Vote for it 😃
Suffian Ahmed you mean your wordpress header right? I have all of this but only inside fluentcommunity.
Think I asked them about that as well a little while ago. They'll probably make it happen.
\<?php
/**
-
Plugin Name: FluentCart Menu Bar Cart
-
Description: 在 WordPress 主题菜单中显示 FluentCart 的购物车图标和商品数量。
-
Version: 1.0.0
-
Author: Your Name
*/
// 防止直接访问文件
if (!defined('ABSPATH')) {
exit;
}
// 注册脚本和样式
function fluentcart_menu_bar_enqueue_assets() {
wp_enqueue_style(
'fluentcart-menu-bar-cart-style',
plugin_dir_url(__FILE__) . 'css/style.css',
\[],
'1.0.0'
);
wp_enqueue_script(
'fluentcart-menu-bar-cart-script',
plugin_dir_url(__FILE__) . 'js/script.js',
\['jquery'],
'1.0.0',
true
);
// 向前端传递购物车信息 (AJAX)
wp_localize_script(
'fluentcart-menu-bar-cart-script',
'FluentCartMenuBar',
\[
'ajax_url' => admin_url('admin-ajax.php'),
]
);
}
add_action('wp_enqueue_scripts', 'fluentcart_menu_bar_enqueue_assets');
// 注册菜单到主题位置
function fluentcart_menu_bar_add_to_menu($items, $args) {
if ($args->theme_location === 'primary') {
$cart_count = fluentcart_menu_bar_get_cart_count(); // 获取购物车数量
$cart_icon = '\<i class="menu-bar-cart-icon">🛒\</i>';
$items .= '\<li class="menu-bar-cart">\<a href="' . esc_url(get_permalink(fluentcart_get_cart_page_id())) . '">' . $cart_icon . ' \<span class="cart-count">' . $cart_count . '\</span>\</a>\</li>';
}
return $items;
}
add_filter('wp_nav_menu_items', 'fluentcart_menu_bar_add_to_menu', 10, 2);
// 获取购物车中的数量 (FluentCart)
function fluentcart_menu_bar_get_cart_count() {
if (!class_exists('\FluentCart\App\Services\CartService')) {
return 0;
}
$cartService = \FluentCart\App\Services\CartService::getInstance();
$cart = $cartService->getCart();
return $cart ? count($cart['items']) : 0;
}
// 添加 AJAX 支持
add_action('wp_ajax_fluentcart_update_cart_count', 'fluentcart_menu_bar_ajax_cart_count');
add_action('wp_ajax_nopriv_fluentcart_update_cart_count', 'fluentcart_menu_bar_ajax_cart_count');
function fluentcart_menu_bar_ajax_cart_count() {
wp_send_json_success([
'cart_count' => fluentcart_menu_bar_get_cart_count()
]);
}
Ming Xu what is that all about. Is that third party plugin share the link here please ?
No plugins now! This script is generated by AI to make a cart icon on menu.
Have you used it? Can you share your live link here to view it. ?
Suffian Ahmed no! I didn't used it on my site.
Fluentcart with the new release they have made one shortcode for cart counter. Short code is [fluent_cart_mini_cart] you can use it directly in header and footer oo. Thanks
Ref - https://fluentcart.com/blog/fluentcart-v1-3-10/ check other details here.