在Woocommerce中,我需要设置结账页面上三个字段的默认排序优先级(sorting):
第一个更改取决于选择了“IT”国家代码:
邮政编码 - 'priority' => 91,
其他两个没有条件,我只需要设置默认优先级:
billing_email - 'priority' => 30,
billing_phone - 'priority' => 40,
通过直接编辑文件,如下所示编辑core文件class-wc-countries.php,我得到了我需要的结果。但是显然,在每次插件更新时,我都会失去这些更改。
现在我正在寻找一个钩子来以清洁的方式完成此操作。
在class-wc-countries.php中(大约在第935行附近):
我将“优先级”值更改为:
第一个更改取决于选择了“IT”国家代码:
邮政编码 - 'priority' => 91,
其他两个没有条件,我只需要设置默认优先级:
billing_email - 'priority' => 30,
billing_phone - 'priority' => 40,
通过直接编辑文件,如下所示编辑core文件class-wc-countries.php,我得到了我需要的结果。但是显然,在每次插件更新时,我都会失去这些更改。
现在我正在寻找一个钩子来以清洁的方式完成此操作。
在class-wc-countries.php中(大约在第935行附近):
IT' => array(
'postcode' => array(
'priority' => 65, // <============= HERE
),
'state' => array(
'required' => true,
'label' => __( 'Province', 'woocommerce' ),
),
),
我将“priority”值从65
更改为91
:
IT' => array(
'postcode' => array(
'priority' => 91, // <============= HERE
),
'state' => array(
'required' => true,
'label' => __( 'Province', 'woocommerce' ),
),
),
在大约1203行附近:
// Add email and phone fields.
if ( 'billing_' === $type ) {
$address_fields['billing_phone'] = array(
'label' => __( 'Phone', 'woocommerce' ),
'required' => true,
'type' => 'tel',
'class' => array( 'form-row-wide' ),
'validate' => array( 'phone' ),
'autocomplete' => 'tel',
'priority' => 100, // <============= HERE
);
$address_fields['billing_email'] = array(
'label' => __( 'Email address', 'woocommerce' ),
'required' => true,
'type' => 'email',
'class' => array( 'form-row-wide' ),
'validate' => array( 'email' ),
'autocomplete'=>'no'===get_option
('woocommerce_registration_generate_username' )
? 'email' : 'email username',
'priority' => 110, // <============= HERE
);
}
我将“优先级”值更改为:
// Add email and phone fields.
if ( 'billing_' === $type ) {
$address_fields['billing_phone'] = array(
'label' => __( 'Phone', 'woocommerce' ),
'required' => true,
'type' => 'tel',
'class' => array( 'form-row-wide' ),
'validate' => array( 'phone' ),
'autocomplete' => 'tel',
'priority' => 40, // <============= HERE
);
$address_fields['billing_email'] = array(
'label' => __( 'Email address', 'woocommerce' ),
'required' => true,
'type' => 'email',
'class' => array( 'form-row-wide' ),
'validate' => array( 'email' ),
'autocomplete'=>'no'===get_option
('woocommerce_registration_generate_username' )
? 'email' : 'email username',
'priority' => 30, // <============= HERE
);
}
非常感谢您的帮助。
is_checkout()
和is_account()
,但如果你使用相同的钩子,请改变钩子的优先级,这是add_action()
和add_filter()
的第三个参数(每次为相同的钩子使用不同的参数)。 - LoicTheAztec