php - woocommerce 购物车为空时隐藏元素,出现在 AJAX 上添加到购物车
问题描述
我有一个 woocommerce 商店,其中购物车中的商品数量显示在标题中的购物车图标旁边。该区域的 CSS 选择器是.woofc-menu-item-inner:after。我目前正在使用下面的代码在购物车为空时隐藏该元素:
// Remove Item Count when Bag is Empty //
add_action('wp_head', 'hook_css', 99999);
function hook_css() {
// If cart is empty hide the item count
if(WC()->cart->is_empty())
echo '<style type="text/css"> .woofc-menu-item-inner:after{display:none !important;}</style>';
}
但是,上面的代码仅适用于页面加载。我目前使用几个插件(Ajax add to cart for WooCommerce,Ajax Cart AutoUpdate for WooCommerce)在不重新加载页面的情况下更新购物车的内容。当使用 AJAX 添加/删除项目时,是否有显示/隐藏此元素?
解决方案
推荐阅读
- python - 用于循环/其他可迭代的 Python 多处理
- c# - 我如何在 C# WPF 中的 ListView 中添加 ContextMenu(当有人右键单击 ListView 项目时想要添加“修改”操作)
- php - 一种使用开关的方法,检查“url/file”中是否存在“url/file”?get.php?[请求uri]
- vue.js - vue.js 基于菜单选择添加动态输入字段
- python - 如何使用来自 python 的请求使用 opencv 从 url 打开图像
- reactjs - 使用 ESLint 时如何修复“意外令牌”?
- javascript - 从 TypeScript 生成 ES6 模块输出,安装 Jest,不会产生错误
- python - 我做错了什么并且可以通过这个程序改进吗?
- powershell - 使用参数测量启动过程的运行时间
- c# - C# Xamarin Forms Listview 将 BindingContext 设置为嵌套列表