You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义Botiga主题中WooCommerce购物车删除按钮postname模式下失效

修复Botiga主题购物车页面删除按钮在postname固定链接模式下失效的问题

问题分析

当WooCommerce固定链接设置为postname时,Botiga主题购物车页面的商品删除按钮失效,但simple模式下正常,且迷你购物车的删除按钮不受影响。核心原因是购物车页面的删除按钮缺少WooCommerce AJAX删除逻辑依赖的remove_from_cart_button类名,而迷你购物车的按钮类名是正确的,因此能正常触发删除请求。

修复方案

方案1:使用WooCommerce钩子修改按钮类名(推荐)

通过woocommerce_cart_item_remove_link过滤器,替换购物车删除按钮的类名,无需修改主题核心文件,避免主题更新丢失修改:

add_filter( 'woocommerce_cart_item_remove_link', 'fix_botiga_cart_remove_button_class', 10, 2 );
function fix_botiga_cart_remove_button_class( $link, $cart_item_key ) {
    // 将原有按钮class替换为'remove remove_from_cart_button'
    return str_replace( 'class="remove"', 'class="remove remove_from_cart_button"', $link );
}

使用方法:

  • 将上述代码添加到子主题的functions.php文件中(优先推荐子主题,避免主题更新覆盖);
  • 或者使用代码片段插件(如Code Snippets)添加这段代码。

方案2:直接修改主题购物车模板(不推荐)

如果主题的购物车模板自定义了删除按钮,可找到主题目录下的woocommerce/cart/cart.php文件,找到删除按钮的HTML代码,将class="remove"修改为class="remove remove_from_cart_button"。

注意:直接修改主题文件会在主题更新时丢失修改,因此优先使用方案1。

验证

添加代码后刷新购物车页面,检查删除按钮的HTML属性,确认class包含remove_from_cart_button,然后测试删除商品功能是否正常。

内容的提问来源于stack exchange,提问作者genreeds48

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 12:52:08