从Woocommerce 3.4+中“我的帐户"编辑地址上的字段中删除(可选)文本 [英] Remove (optional) text from fields on My account edit address in Woocommerce 3.4+

查看:171
本文介绍了从Woocommerce 3.4+中“我的帐户"编辑地址上的字段中删除(可选)文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从WooCommerce我的帐户编辑地址页面中删除<span class="optional">(optional)</span>.还有其他方法可以做到这一点吗?

I'm trying to remove the <span class="optional">(optional)</span> from the WooCommerce My Account edit address page. Is there an other way to do it like this?

.optional {
    display: none;
}

我认为最好以DOM形式将其完全从DOM中删除.

I think it would be better to remove it completely from the DOM in the form.

我该怎么做?

推荐答案

要从我的帐户编辑地址的字段中删除"(可选)" 标签文本,请使用以下代码:

To remove "(optional)" label text from fields in my account edit address, use the following code:

// Remove "(optional)" from  non required fields (in My account edit address)
add_filter( 'woocommerce_form_field' , 'remove_checkout_optional_fields_label', 10, 4 );
function remove_checkout_optional_fields_label( $field, $key, $args, $value ) {
    if( is_wc_endpoint_url( 'edit-address' ) ){
        $optional = '&nbsp;<span class="optional">(' . esc_html__( 'optional', 'woocommerce' ) . ')</span>';
        $field = str_replace( $optional, '', $field );
    }
    return $field;
}

代码进入活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of the active child theme (or active theme). Tested and works.

相关:删除"(可选)" Woocommerce 3.4+

这篇关于从Woocommerce 3.4+中“我的帐户"编辑地址上的字段中删除(可选)文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆