首页 文章

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

提问于
浏览
0

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

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

我附上了截图,以更好地表达我需要做的事情 . 很遗憾,我在文档中找不到任何相关信息 .

1 回答

  • 2

    以下代码将附加到结帐页面中的网关描述,自定义文本输入字段(此处为此示例为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, $method_id ){
        //
        if( $method_id == 'bacs' ){
            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;
    }
    

    代码位于活动子主题(或活动主题)的function.php文件中 . 测试和工作 .

相关问题