在我的函数中,我正在尝试执行以下操作:
if ( !empty( $fields['billing']['billing_phone'] ) ) {
$fields['billing']['billing_phone']['custom_attributes'] = array('disabled'=>'disabled');
}
elseif ( empty( $fields['billing']['billing_phone'] ) ) {
// Here's my problem. I don't know how to unset, disable or delete that array previously added.
}
我要在此处存档的是,如果该字段为空,则用户应该只能首次添加信息。
谢谢!
我自己的解决方案:
重要提示:别忘了删除/忽略以前的代码(该方法对我不起作用)。
我刚刚在结帐页面中添加了此javascript。
jQuery(document).ready(function($){
$('input[name*=billing_phone_no]').map(function()
{
if( $(this).val() ) {
$(this).attr("disabled", 'disabled');
$(this).addClass('notactive');
}
});
});
CSS:除了背景色,似乎这不是必需的,您可以尝试不使用CSS。
input.notactive {
background: #eee !important;
pointer-events: none;
cursor: default;
}
多个输入
如果您需要同时对多个输入执行相同的操作,则可以更改此行:
$('input[name*=billing_phone_no]').map(function()
为此:
$('input[name*=billing_phone_no], input[name*=billing_phone_digt_countrycode], input[name*=billing_email]').map(function()
也许这不是完美/最干净的解决方案,如果您知道如何进行改进,请告诉我:)
仍在寻求帮助:有谁知道PHP / functions方法非常完美!