微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Woocommerce中特定支付网关结账时的附加字段

我有一个自定义的Woocommerce支付网关,我需要在选中付款时在结账时添加额外的字段.

基本上,当用户点击自定义支付网关时,应出现“选择”字段,他们必须从选择字段中选择一些内容.

我附上了一个截图,以更好地表达我需要做的事情.不幸的是,我在文档中找不到任何关于它的信息.

this is the image

解决方法:

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

// 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文件中.测试和工作.

enter image description here

Related: 07001

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

07002

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐