在Woocommerce中,我需要在结帐页面上设置三个字段的默认排序优先级(排序):
第一个更改取决于 'IT' 国家/地区代码的选择:
- 邮政编码 - 'priority' => 91,
其他两个没有条件,我只需要设置默认优先级:
-
billing_email - 'priority' => 30,
-
billing_phone - 'priority' => 40,
通过直接编辑文件,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的第120行:
// 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
);
}
我将'priority'值更改为:
// 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
);
}
任何帮助表示赞赏 .
1 回答
使用可用的过滤器挂钩,您可以在不覆盖核心文件的情况下进行更改...
第一个更改是使用此挂钩的佣人(对于"IT"国家/地区代码):
第二次改变 you need also to change the class . 它与您在回答其他问题时已经拥有的代码相同,但不删除此行:
代码是:
所以你可以使用(对于帐户和结帐页面):
代码位于活动子主题(或活动主题)的function.php文件中 . 经过测试和工作 .