gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 22:58:39 25 4
gpt4 key购买 nike

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

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

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

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: 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

关于php - Woocommerce 中特定支付网关结账时的附加字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52164954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com