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

如何在Gravity Forms输入字段中隐藏欧元货币符号

解决Gravity Forms自定义金额字段隐藏欧元符号的问题

以下是几个可行的解决方案,按实现复杂度和推荐程度排序:

方案1:CSS直接隐藏符号(最简便)

Gravity Forms通常会把货币符号放在输入框旁边的独立元素里,直接用CSS隐藏即可,不会影响输入框功能:

/* 隐藏Gravity Forms自定义金额字段的欧元符号 */
.gravityforms .ginput_amount_container .gfield_currency {
    display: none !important;
}

将这段代码添加到主题的自定义CSS面板(Appearance > Customize > Additional CSS),或者主题的style.css文件中。

方案2:修正jQuery代码(保留预定义值)

你之前的jQuery代码存在两处问题:用text()获取输入框内容(输入框应使用val()),且仅在点击时触发,未处理页面加载时的初始值和动态渲染的字段。修正后的代码如下:

jQuery(document).ready(function($) {
    // 处理页面加载时已渲染的字段
    $('.ginput_amount').each(function() {
        var currentValue = $(this).val().replace('€', '');
        $(this).val(currentValue);
    });

    // 处理AJAX加载的表单(如多页表单、动态生成的字段)
    $(document).on('gform_post_render', function() {
        $('.ginput_amount').each(function() {
            var currentValue = $(this).val().replace('€', '');
            $(this).val(currentValue);
        });
    });
});

将这段代码添加到主题的footer.php文件末尾(</body>标签前),或通过自定义JS插件注入。

方案3:PHP钩子从源头修改(最彻底)

之前的gform_currencies过滤器可能因优先级较低被覆盖,或需要针对特定字段调整,尝试以下两种方式:

方式A:提高过滤器优先级

add_filter( 'gform_currencies', 'remove_eur_currency_symbols', 100 );
function remove_eur_currency_symbols( $currencies ) {
    if ( isset( $currencies['EUR'] ) ) {
        $currencies['EUR']['symbol_left'] = '';
        $currencies['EUR']['symbol_right'] = '';
    }
    return $currencies;
}

将这段代码添加到主题的functions.php文件,或自定义功能插件中。

方式B:针对产品字段单独修改

如果仅需隐藏特定自定义金额产品字段的符号,使用gform_pre_render钩子:

add_filter( 'gform_pre_render', 'remove_custom_amount_currency_symbol', 10, 2 );
function remove_custom_amount_currency_symbol( $form, $ajax ) {
    foreach ( $form['fields'] as &$field ) {
        // 匹配启用自定义金额的产品字段
        if ( $field->type === 'product' && $field->inputType === 'single' && ! empty( $field->enablePrice ) ) {
            $field->currencySymbol = '';
        }
    }
    return $form;
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 20:50:26