id怎么添加付款方式

将 ID 列添加到 WooCommerce 付款方式列表

WooCommerce 是一个功能强大的电子商务插件,它允许您在您的网站上创建一个完整的在线商店,WooCommerce 提供了多种付款方式,如信用卡、借记卡、PayPal 等,如果您想要在 WooCommerce 的付款方式列表中添加一个新的付款方式,例如将 ID 列添加到付款方式列表中,您需要进行一些设置和编程工作,本文将详细介绍如何将 ID 列添加到 WooCommerce 付款方式列表,并提供一些相关问题与解答。

id怎么添加付款方式

准备工作

1、1 备份数据库

在进行任何更改之前,请确保备份您的数据库,这可以防止在更改过程中出现任何问题时导致数据丢失。

1、2 安装并激活 WooCommerce

如果您还没有安装 WooCommerce,请按照官方文档的指示进行安装,安装完成后,请激活插件。

添加自定义字段到付款方式表单

2、1 进入 WordPress 后台

登录到您的 WordPress 后台,然后转到“设置”>“更多设置”>“自定义字段”。

id怎么添加付款方式

2、2 添加自定义字段

点击“添加新字段”,然后输入以下信息:

字段名称:payment_method_id(或其他您喜欢的名称)

字段类型:文本(或其他适当的类型,例如选择或复选框)

选项值:无(或其他适当的选项值,是”或“否”)

描述:ID 列(或其他适当的描述)

id怎么添加付款方式

单击“添加到定制器”按钮以保存字段,现在,您已经成功添加了一个自定义字段到付款方式表单。

修改付款方式类文件以显示自定义字段

3、1 创建新的 PHP 文件

在您的主题文件夹中创建一个名为“custom-payment-methods.php”的新文件,在此文件中,我们将编写代码来显示自定义字段。

3、2 编辑 custom-payment-methods.php 文件

打开“custom-payment-methods.php”文件,然后将以下代码粘贴到文件中:

<?php if ( 'checkout' === $context && isset( $_GET['paypal_redirect'] ) && $_GET['paypal_redirect'] === 'yes' ) { ?>
  <div class="woocommerce-payment-methods">
    <?php foreach ( wc_get_order_payment_methods() as $key => $value ) { ?>
      <?php if ( 'checkout' === $value->get_checkout_field() || isset( $_GET['paypal_redirect'] ) && $_GET['paypal_redirect'] === 'yes' ) { ?>
        <h3><?php echo $value->get_title(); ?></h3>
        <ul class="wc-payment-methods">
          <?php foreach ( $value->get_payment_gateways() as $gateway ) { ?>
            <?php if ( method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method_exists( $gateway, 'get_option' ) && method__( 'ID: %s', gettext__( 'PayPal Standard Payment Gateway (with ID column added): %s', '' /* translators: payment gateway name */), gettext__( 'PayPal Standard Payment Gateway (with ID column added): %s', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)', '' /* translators: payment gateway name */), gettext__( '%s (ID: %s)';?> <li><?php echo stripe\$value->id;?></li> <?php endforeach;} </ul> </h3> <?php endif;}?> </div> <?php endforeach;} elseif ($context === 'checkout'){?> <div class="woocommerce-checkout" style="display:none;"> <form action="" method="post" id="woocommerce-checkout-form" class="woocommerce-form-wrapper" novalidate=""> <div class="woocommerce-form-row form-row form-row-expanded checkout-payment clearfix"> <div class="woocommerce-form-field validate-required"> <label for="payment"><span class="help-inline"></span></label></div> <div class="woocommerce-form-field"> <select class="wc-payment-method" id="payment" name="payment"> <?php foreach ( \WC()->payment->get_source()->all() as \WC()->payment->instance() as \$instance): // Get the source of the current order and set it to the instance variable. echo '<option value="pagseguro">PagSeguro</option>'; echo '<option value="creditcard">Credit Card</option>'; echo '<option value="debitcard">Debit Card</option>'; echo '<option value="banktransfer">Bank Transfer</option>'; echo '<option value="paypal">PayPal Standard Payment Gateway</option>'; echo '<option value="paypalexpress">PayPal

原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/228616.html

(0)
K-seoK-seoSEO优化员
上一篇 2024年1月19日 02:20
下一篇 2024年1月19日 02:21

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入