首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >签出字段-使billing_address_2高于billing_address_1

签出字段-使billing_address_2高于billing_address_1
EN

Stack Overflow用户
提问于 2017-02-06 12:08:50
回答 1查看 2.3K关注 0票数 3

在WooCommerce签出字段中,我试图在签出表单上使billing_address_2高于billing_address_1。

所以与其说它是:

代码语言:javascript
复制
Street Address
Apartment

我希望:

代码语言:javascript
复制
Apartment
Street Address

请注意,我使用的主题叫做Avada。

我怎样才能做到这一点?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-06 13:05:07

更新(与您的评论相关)…

这里添加了一个从Address1字段中删除"Address“文本标签并将其设置为Address2字段的附加项,这也使该字段(可选)成为必需的,并稍微更改了位置持有者…。我还有另一个解决方案(请参阅下面的代码)。

以下是代码:

代码语言:javascript
复制
add_filter( 'woocommerce_checkout_fields', 'custom_billing_fields_order' );
function custom_billing_fields_order( $fields ) {

    // 1. Customizing address_1 and address_2 fields
    $fields['billing']['billing_address_1']['label'] = ''; // Removing the label from Adress1
    $fields['billing']['billing_address_2']['label'] = __('Address', 'theme_domain');
    $fields['billing']['billing_address_2']['required'] = true; // Making Address 2 field required
    $fields['billing']['billing_address_2']['placeholder'] = __('Apartment, suite, unit etc...', 'woocommerce');

    // 2. Custom ordering the billing fields array (toggling address_1 with address_2)
    $custom_fields_order = array(
        'billing_first_name', 'billing_last_name',
        'billing_company',
        'billing_email',      'billing_phone',
        'billing_country',
        'billing_address_2',  'billing_address_1',  ##  <== HERE, changed order
        'billing_postcode',   'billing_city'
    );

    foreach($custom_fields_order as $field)
        $new_ordered_fields[$field] = $fields['billing'][$field];

    // Replacing original fields order by the custom one
    $fields['billing'] = $new_ordered_fields;


    // Returning Checkout customized billing fields order
    return $fields;
}

而不是切换这两个字段,您可以反转字段占位符并添加make (可选)字段Address2,因此不需要重新排序字段。你可以这样做:

代码语言:javascript
复制
add_filter( 'woocommerce_checkout_fields', 'custom_billing_fields_placeholders' );
function custom_billing_fields_placeholders( $fields ) {

    // 1. Customizing address_1 and address_2 fields
    $fields['billing']['billing_address_1']['placeholder'] = __('Apartment, suite, unit etc...', 'woocommerce');
    $fields['billing']['billing_address_2']['required'] = true; // Making Address 2 field required
    $fields['billing']['billing_address_2']['placeholder'] = __('Street address', 'woocommerce');

    // Returning Checkout customized billing fields
    return $fields;
}

代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。

代码经过测试和工作。

相关答案:签出字段:隐藏和显示现有字段

正式文件:使用操作和过滤器自定义签出字段

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42067445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档