Remove (optional) text from fields on My account e

2019-06-05 03:32发布

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;
}

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

How can I do this?

1条回答
爷的心禁止访问
2楼-- · 2019-06-05 04:26

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;
}

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

Related: Remove "(optional)" text from checkout fields in Woocommerce 3.4+

查看更多
登录 后发表回答