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

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

问题描述

我有一个自定义Woocommerce支付网关,我需要在选择付款时在结账时添加其他字段.

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

我附上了一张截图,以更好地表达我需要做什么的想法.不幸的是,我在文档中找不到任何相关信息.

解决方案

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

//BACS 支付网关说明:附加自定义选择字段add_filter( 'woocommerce_gateway_description', 'gateway_bacs_custom_fields', 20, 2 );函数 gateway_bacs_custom_fields( $description, $payment_id ){//if('bacs' === $payment_id ){ob_start();//开始缓冲echo '

';woocommerce_form_field( 'field_slug', array('类型' =>'选择','标签' =>__(填写此字段",woocommerce"),'类' =>数组('表格行宽'),'必需' =>错误的,'选项' =>大批('' =>__(选择一些东西",woocommerce"),'选择-1' =>__(选择一个",woocommerce"),'选择 2' =>__(选择二",woocommerce"),),), '');echo '

';$description .= ob_get_clean();//添加缓冲内容}返回 $ 描述;}

代码位于活动子主题(或活动主题)的 functions.php 文件中.经测试有效.

<块引用>

相关:验证并保存 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.

解决方案

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;
}

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

Related: Validate and save additional checkout field for specific payment gateway in Woocommerce


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

Save and display specific payment gateway additional field everywhere in Woocommerce

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

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