- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Woocommerce 中,我需要在结帐页面上设置三个字段的默认排序优先级(排序):
第一个变化取决于'IT'
国家代码的选择:
另外两个是无条件的,我只需要设置默认优先级即可:
通过直接编辑文件,class-wc-countries.php核心文件如下所示,我得到了我需要的东西。但很明显,每次更新插件时,我都会丢失更改。
现在我正在寻找一个钩子(Hook)来以干净的方式完成这项工作。
在class-wc-countries.php (大约第 935 行)来自:
IT' => array(
'postcode' => array(
'priority' => 65, // <============= HERE
),
'state' => array(
'required' => true,
'label' => __( 'Province', 'woocommerce' ),
),
),
我将“优先级”值从 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
);
}
感谢任何帮助。
最佳答案
使用可用的过滤器 Hook ,您可以在不覆盖核心文件的情况下进行更改……
第一个更改是使用此 Hook (针对“IT”国家/地区代码):
add_filter('woocommerce_get_country_locale', 'custom__country_locale', 30, 1 );
function wps_select_order_meta_keys( $locale ) {
$locale['IT']['postcode']['priority'] = 91;
return $locale;
}
对于第二个更改您还需要更改类。它与您在其他问题的答案中已经拥有的代码相同,但没有删除这一行:
if( ! is_account_page() ) return $fields;
代码是:
add_filter( 'woocommerce_billing_fields', 'custom_billing_fields', 20, 1 );
function custom_billing_fields( $fields ) {
## ---- 1. Sort billing email and phone fields ---- ##
$fields['billing_email']['priority'] = 30;
$fields['billing_email']['class'] = array('form-row-first');
$fields['billing_phone']['priority'] = 40;
$fields['billing_phone']['class'] = array('form-row-last');
return $fields;
}
So if you remove
if( ! is_account_page() ) return $fields;
from the code in my other answer, it will work also on checkout page (as as already indicated)…
因此您可以使用(用于帐户和结帐页面):
add_filter( 'woocommerce_default_address_fields', 'custom_default_address_fields', 20, 1 );
function custom_default_address_fields( $fields ) {
## ---- 1. Remove 'address_2' field ---- ##
unset($fields['address_2']);
## ---- 2. Sort Address fields ---- ##
// Set the order (sorting fields) in the array below
$sorted_fields = array('first_name','last_name','company','address_1','country','postcode','city','state');
$new_fields = array();
$priority = 0;
// Reordering billing and shipping fields
foreach($sorted_fields as $key_field){
$priority += 10;
if( $key_field == 'company' )
$priority += 20; // keep space for email and phone fields
$new_fields[$key_field] = $fields[$key_field];
$new_fields[$key_field]['priority'] = $priority;
}
return $new_fields;
}
代码进入事件子主题(或事件主题)的 function.php 文件。经过测试并有效。
关于php - 根据国家/地区对特定 Woocommerce 结帐字段的排序优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49658749/
这个问题在这里已经有了答案: Where am I? - Get country (10 个答案) How can I get my Android device country code with
有办法检查吗?我有一个应用程序 URL,除非用户有英国应用商店,否则我不想打开该 URL。不幸的是,这个应用程序在许多国家/地区都可用,因此当我在链接上添加“gb”时,它会被重定向到用户的本地区域。
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足 Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以
获取设备当前区域的最佳方法是什么?假设用户在德国并使用意大利语作为设备语言。如果我使用 Locale.getDefault(),那么国家和语言就会相互映射,即语言是it,国家是IT。我想要的是它和DE
有人可以给我一个示例或教程,其中显示国家及其代码的下拉列表我的代码显示错误的新西兰语言代码,它显示 mi-NZ 而不是 en-NZ ASP.NET protected void Page_Load(o
我是 Ajax 和 PHP 的新手,遇到动态下拉国家和州的问题。 虽然我已经检查了 stackOverflow 中的所有答案,但我无法清楚地了解我们应该如何成功地编写代码以获得所需的结果。 count
我一直在开发一个注册表单应用程序,其中使用了几个微调器小部件。微调器用于选择国家、州和城市。因此,这些微调器需要以某种方式相互连接(下面的代码将展示我如何尝试实现这一点)。 表单代码: fragmen
如果你去http://profile.microsoft.com并编辑您的个人信息,您将选择您的国家。选择国家/地区后,城市和/或州信息会根据该国家/地区的预期变化。有没有人有任何关于如何实现这一目标
我有一个带有经纬度坐标的 data.frame: df<-data.frame( lat=c(40, 30, 40.864), lon=c(0, 20, 1.274) )
我正在尝试在将与 django-allauth 一起使用的注册表中添加 django-countries。按照说明 https://github.com/SmileyChris/django-coun
嗨,我想为国家和州实现下拉列表。州下拉列表应根据所选国家/地区更改其值。 是否有任何插件或 gem 可以在 Rails 中执行此操作。 最佳答案 试试卡门插件: http://autonomousma
我的服务器上安装了基于PHP的Youtube克隆系统。 几个国家使用相同的系统。假设我有3个域都指向同一系统: www.site.hr www.site.ba www.site.rs 他们都重定向到一
在我的 Azure DNS 和域提供商中设置后,我想使用我的国家/地区域名 mydomain.id,但我仍然无法在应用服务中验证我的域。我已经仔细检查了所有内容,我认为我的设置已经正确。现在我想知道我
最近,我们开始遇到向网络应用程序的用户呈现过时的国家/地区列表的问题。 我们目前有一些数据库表来存储本地化的国家/地区名称及其地区(州)。然而,随着地球的发展,该列表在不断演变,并且事实证明维护起来很
This is the third iteration of this question as errors have been solved (在一些人的感激帮助下)。为了避免对到底发生了什么感到困
全部, 我们的应用程序需要有关 ISO 国家和货币的数据(其中数据必须是最新的)。我们确实从 ISO 自己购买了国家/货币数据,但是我们仍然需要对数据执行大量手动操作,以及编写我们自己的工具来读取数据
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我想使用 PHP 和 jQuery 执行以下操作 https://www.careerbuilder.com/share/register.aspx?sc_cmp1=JS_LoginASPX_RegN
假设我们有一个包含所有国家/地区代码的代码列表。国家代码是 Countries 表的主键,它在数据库中的许多地方用作外键。在我的应用程序中,国家通常显示为多个表单的下拉列表。 一些过去曾经存在的国家不
我想根据语言环境获取当前日期/时间。如果我传递 locale 对象,我需要获取国家/地区的相关日期/时间。 最佳答案 从 Java 8 开始,您有 LocalDateTime 和 ZonedDateT
我是一名优秀的程序员,十分优秀!