Woocommerce中特定付款网关的结帐附加字段 [英] Additional field on checkout for specific payment gateway in Woocommerce

查看:137
本文介绍了Woocommerce中特定付款网关的结帐附加字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的Woocommerce付款网关,选择付款后,我需要在结帐栏上添加其他字段.

I have a custom Woocommerce payment gateway and I need to add additional field on the checkout when the payment is selected.

基本上,当用户单击自定义支付网关时,将出现选择"字段,他们必须从选择字段中进行选择.

Basically, when the users click the custom payment gateway a "select" field should appear and they have to choose something from the select field.

我附上了一张截图,以更好地表达我需要做的事情的想法.不幸的是,我在文档中找不到有关此信息.

I have attached a screenshot to represent better the idea of what I need to do. Unfortunately, I couldn't find any info about that in the Docs.

推荐答案

以下代码将添加到结帐页面中网关描述的自定义文本输入字段(在此示例中,是BACS付款网关):

The following code will append to the gateway description in checkout page, a custom text input field (here, in this example to BACS payment gateway):

// BACS payement gateway description: Append custom select field
add_filter( 'woocommerce_gateway_description', 'gateway_bacs_custom_fields', 20, 2 );
function gateway_bacs_custom_fields( $description, $payment_id ){
    //
    if( 'bacs' === $payment_id ){
        ob_start(); // Start buffering

        echo '<div  class="bacs-fields" style="padding:10px 0;">';

        woocommerce_form_field( 'field_slug', array(
            'type'          => 'select',
            'label'         => __("Fill in this field", "woocommerce"),
            'class'         => array('form-row-wide'),
            'required'      => false,
            'options'       => array(
                ''          => __("Select something", "woocommerce"),
                'choice-1'  => __("Choice one", "woocommerce"),
                'choice-2'  => __("Choice two", "woocommerce"),
            ),
        ), '');

        echo '<div>';

        $description .= ob_get_clean(); // Append buffered content
    }
    return $description;
}

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

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

相关:验证并保存Woocommerce中特定付款网关的其他结帐字段


完整方法,验证字段,将其保存为订单自定义元数据,并在订单和电子邮件通知中显示:

The complete way, validating the field, saving it as order custom meta data and display it on orders and email notifications:

在Woocommerce的任何地方保存并显示特定的支付网关附加字段

这篇关于Woocommerce中特定付款网关的结帐附加字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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