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

WordPress+WooCommerce+CartFlows:结算下单按钮文本修改失效求助

解决WooCommerce+CartFlows结算按钮文本被覆盖的问题

1. 修正PHP钩子代码(优先尝试)

你之前的代码存在语法错误(函数缺少左花括号),且使用了错误的钩子。替换为以下兼容WooCommerce和CartFlows的代码:

// 修改WooCommerce默认下单按钮文本
add_filter( 'woocommerce_order_button_text', 'custom_checkout_button_text' );
function custom_checkout_button_text() {
    return __( 'Kupuję i przyciągam obfitość!', 'woocommerce' );
}

// 针对CartFlows的专属钩子(若上述钩子无效时使用)
add_filter( 'cartflows_checkout_place_order_button_text', 'custom_cartflows_checkout_button_text' );
function custom_cartflows_checkout_button_text() {
    return __( 'Kupuję i przyciągam obfitość!', 'woocommerce' );
}

2. 处理JS动态覆盖问题

如果PHP代码无效,说明页面加载后有脚本(如WooCommerce结算更新脚本、CartFlows动态脚本)覆盖了按钮文本,可通过自定义JS强制修改:

方法1:通过functions.php添加内联脚本

add_action( 'wp_footer', 'force_update_checkout_button_text' );
function force_update_checkout_button_text() {
    // 仅在结算页加载脚本
    if ( is_checkout() && ! is_wc_endpoint_url() ) {
        ?>
        <script>
        // 等待页面完全加载后执行
        document.addEventListener('DOMContentLoaded', function() {
            const placeOrderBtn = document.getElementById('place_order');
            if (placeOrderBtn) {
                placeOrderBtn.textContent = 'Kupuję i przyciągam obfitość!';
                // 监听结算页面更新事件,防止按钮被重新渲染后变回默认
                document.body.addEventListener('updated_checkout', function() {
                    const updatedBtn = document.getElementById('place_order');
                    if (updatedBtn) {
                        updatedBtn.textContent = 'Kupuję i przyciągam obfitość!';
                    }
                });
            }
        });
        </script>
        <?php
    }
}

方法2:直接添加自定义JS(快速方案)

在CartFlows自定义HTML模块或主题自定义JS面板中加入这段代码:

document.addEventListener('DOMContentLoaded', function() {
    const btn = document.getElementById('place_order');
    if (btn) {
        btn.innerHTML = 'Kupuję i przyciągam obfitość!';
        // 监听结算更新事件,避免按钮重置
        document.body.addEventListener('updated_checkout', function() {
            const updatedBtn = document.getElementById('place_order');
            if (updatedBtn) {
                updatedBtn.innerHTML = 'Kupuję i przyciągam obfitość!';
            }
        });
    }
});

3. 排查插件/主题冲突

若以上方法均无效,可进行以下排查:

  • 暂时禁用除WooCommerce、CartFlows外的所有插件,测试按钮文本是否正常。
  • 切换到WordPress默认主题(如Twenty Twenty-Three),排除主题自定义代码的影响。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 16:22:18