在WooCommerce的姓氏下添加自定义结帐单字段 [英] add a custom checkout billing field under the last name in WooCommerce

查看:78
本文介绍了在WooCommerce的姓氏下添加自定义结帐单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WooCommerce中,我在结帐帐单字段部分的末尾添加了一个自定义帐单字段,代码如下:

In WooCommerce I am adding a custom billing field at the end of the checkout billing fields section, with the code below:

add_filter('woocommerce_checkout_fields', 'custom_woocommerce_billing_fields');

function custom_woocommerce_billing_fields($fields)
{
         $fields['billing']['billing_options'] = array(
        'label' => __('תאריך לידה', 'woocommerce'), // Add custom field label
        'placeholder' => _x('תאריך לידה'), // Add custom field placeholder
        'required' => true, // if field is required or not
        'clear' => false, // add clear or not
        'type' => 'date', // add field type
        'class' => array('my-css')   // add class name
    );

    return $fields;
}

如何在姓氏字段或公司字段之后添加此字段?

How can I add this field after the first name last name field or after company field?

推荐答案

您需要使用"priority"参数,该参数可让您将字段设置在正确的位置(在名字和姓氏字段之后).

You need to use the "priority" argument, which will allow you to set your field in the correct location (after the first and last name fields).

通常,计费名字"优先级为 10 ,而计费姓氏 20 .然后出现计费公司",其优先级为 30 ...因此,对于您的自定义结算字段,请使用优先级为 25 (介于两者之间).

Normally "billing first name" has a 10 as priority and "billing last name 20 as priority. Then comes the "billing company" that has 30 as priority… So for your custom billing field use a priority of 25 (in between).

您的代码中应该替换> _x() > __() .

There is a little mistake in your code for the placeholder where you should replace _x() function by __().

您的代码将是:

add_filter('woocommerce_checkout_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields( $fields )
{
    $fields['billing']['billing_options'] = array(
        'label'       => __('תאריך לידה', 'woocommerce'), // Add custom field label
        'placeholder' => __('תאריך לידה', 'woocommerce'), // Add custom field placeholder
        'required'    => true, // if field is required or not
        'clear'       => false, // add clear or not
        'type'        => 'date', // add field type
        'class'       => array('my-css'),   // add class name
        'priority'    => 25, // Priority sorting option
    );

    return $fields;
}

代码进入您的活动子主题(或活动主题)的functions.php文件中.经过测试,可以正常工作.

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

如果您想在计费公司之后填写此字段,则将使用优先级 35 .

If you want this field after the billing company, you will use a priority of 35 instead.

相关:在WooCommerce 3中对结帐字段进行重新排序

这篇关于在WooCommerce的姓氏下添加自定义结帐单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆