【发布时间】:2021-05-09 22:12:56
【问题描述】:
首先,我自己不是编码员,因此我与您分享的代码是我自己创建的,通过在这里和那里复制来尝试使其工作......但事实并非如此。那你能帮帮我吗?
我正在尝试:将 billing_phone 设为 autocomplete="tel" 值,变为 automplete="nope",这样它将停止自动完成该文件,并且只自动完成该文件。
在过去的 10 个小时里我尝试了很多东西,但都没有运气,所以这是我现在在 functions.php 文件中得到的结果,虽然它可能完全错误,但我只是希望你可以帮助我,当然,欢迎您解释您的代码:
/* Disable autofill phone */
add_action('woocommerce_billing_fields', 'autocomplete_nope');
function autocomplete_nope( $content ) {
$str_pos = strpos( $content, 'name="billing_phone"' );
$content = substr_replace( $content, 'value autocomplete="nope"', $str_pos, 0 );
return $content;
}
更新
根据您下面的回答,我尝试了这 2 个选项,但仍然没有运气,他们仍然在 HTML 中发回这个:
<input type="tel" class="input-text wfacp-form-control" name="billing_phone" id="billing_phone" placeholder="999-999-9999" value="" autocomplete="tel">
第一次尝试(不工作):
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields )
{
$fields['billing']['billing_phone']['custom_attributes'] = array( "autocomplete" => "nope" );
return $fields;
}
更新 - 第二次尝试(无效):
add_action('woocommerce_billing_fields', 'autocomplete_nope');
function autocomplete_nope( $fields ) {
$fields['billing']['billing_phone']['autocomplete'] = false;
return $fields;
}
非常感谢您的宝贵时间。
【问题讨论】:
-
能否请您检查一下 - stackoverflow.com/questions/31653634/…。也许对你有帮助。
-
在你的钩子函数中试试这个(在里面删除你的代码):
$fields['billing']['billing_phone']['autocomplete'] = false;其中变量$content应该被$fields替换。 -
建议的链接似乎与我需要的非常相似,但也无法使其正常工作。 Loic,我已经完成了(或者至少认为这是您的建议)但仍然无法正常工作,请检查我的问题的编辑,看看这是否是您的意思。
-
我已经更新了你最后的代码……现在就试试吧
-
仍然没有运气,虽然我为我的商店使用了一个特定的插件,但它下面使用了 woocommerce,所以我认为这不会影响。但是你的代码的结果仍然是一样的。
标签: php wordpress woocommerce autofill