php WooCommerce自定义支付网关未显示在结帐

nuypyhwy  于 2024-01-05  发布在  PHP
关注(0)|答案(1)|浏览(205)

我试图使用WooCommerce自定义支付网关插件。我添加了在 Jmeter 板中显示插件所需的详细信息。
我已经尝试了另一个插件https://wordpress.org/plugins/wc-gateway-cib,但它也没有显示在结帐页面.

  1. <?php
  2. /**
  3. * Plugin Name: Noob Payment for Woocommerce
  4. * Plugin URI: https://omukiguy.com
  5. * Author Name: Laurence Bahiirwa
  6. * Author URI: https://omukiguy.com
  7. * Description: This plugin allows for local content payment systems.
  8. * Version: 0.1.0
  9. * License: 0.1.0
  10. * License URL: http://www.gnu.org/licenses/gpl-2.0.txt
  11. * text-domain: noob-pay-woo
  12. */
  13. if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) return;
  14. add_action( 'plugins_loaded', 'noob_payment_init', 11 );
  15. function noob_payment_init() {
  16. if( class_exists( 'WC_Payment_Gateway' ) ) {
  17. class WC_Noob_pay_Gateway extends WC_Payment_Gateway {
  18. public function __construct() {
  19. $this->id = 'noob_payment';
  20. $this->icon = apply_filters( 'woocommerce_noob_icon', plugins_url('/assets/icon.png', __FILE__ ) );
  21. $this->has_fields = false;
  22. $this->method_title = __( 'Noob Payment', 'noob-pay-woo');
  23. $this->method_description = __( 'Noob local content payment systems.', 'noob-pay-woo');
  24. $this->title = $this->get_option( 'title' );
  25. $this->description = $this->get_option( 'description' );
  26. $this->instructions = $this->get_option( 'instructions', $this->description );
  27. $this->init_form_fields();
  28. $this->init_settings();
  29. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
  30. }
  31. public function init_form_fields() {
  32. $this->form_fields = apply_filters( 'woo_noob_pay_fields', array(
  33. 'enabled' => array(
  34. 'title' => __( 'Enable/Disable', 'noob-pay-woo'),
  35. 'type' => 'checkbox',
  36. 'label' => __( 'Enable or Disable Noob Payments', 'noob-pay-woo'),
  37. 'default' => 'no'
  38. ),
  39. 'title' => array(
  40. 'title' => __( 'Noob Payments Gateway', 'noob-pay-woo'),
  41. 'type' => 'text',
  42. 'default' => __( 'Noob Payments Gateway', 'noob-pay-woo'),
  43. 'desc_tip' => true,
  44. 'description' => __( 'Add a new title for the Noob Payments Gateway that customers will see when they are in the checkout page.', 'noob-pay-woo')
  45. ),
  46. 'description' => array(
  47. 'title' => __( 'Noob Payments Gateway Description', 'noob-pay-woo'),
  48. 'type' => 'textarea',
  49. 'default' => __( 'Please remit your payment to the shop to allow for the delivery to be made', 'noob-pay-woo'),
  50. 'desc_tip' => true,
  51. 'description' => __( 'Add a new title for the Noob Payments Gateway that customers will see when they are in the checkout page.', 'noob-pay-woo')
  52. ),
  53. 'instructions' => array(
  54. 'title' => __( 'Instructions', 'noob-pay-woo'),
  55. 'type' => 'textarea',
  56. 'default' => __( 'Default instructions', 'noob-pay-woo'),
  57. 'desc_tip' => true,
  58. 'description' => __( 'Instructions that will be added to the thank you page and odrer email', 'noob-pay-woo')
  59. ),
  60. ));
  61. }
  62. public function process_payments( $order_id ) {
  63. }
  64. }
  65. }
  66. }
  67. add_filter( 'woocommerce_payment_gateways', 'add_to_woo_noob_payment_gateway');
  68. function add_to_woo_noob_payment_gateway( $gateways ) {
  69. $gateways[] = 'WC_Noob_pay_Gateway';
  70. return $gateways;
  71. }

字符串
我已经在woo-commerce设置中启用了付款->付款,但它没有显示在结帐页面x1c 0d1x WordPress版本是4.6.2

kjthegm6

kjthegm61#

您的代码中有一些错误和遗漏。请尝试以下修改后的代码:

  1. <?php
  2. /**
  3. * Plugin Name: Noob Payment for Woocommerce
  4. * Plugin URI: https://omukiguy.com
  5. * Author Name: Laurence Bahiirwa
  6. * Author URI: https://omukiguy.com
  7. * Description: This plugin allows for local content payment systems.
  8. * Version: 0.1.0
  9. * License: 0.1.0
  10. * License URL: http://www.gnu.org/licenses/gpl-2.0.txt
  11. * text-domain: noob-pay-woo
  12. */
  13. defined( 'ABSPATH' ) or exit;
  14. if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
  15. return;
  16. }
  17. add_action( 'plugins_loaded', 'noob_payment_init', 11 );
  18. function noob_payment_init() {
  19. if( class_exists( 'WC_Payment_Gateway' ) ) {
  20. class WC_Noob_pay_Gateway extends WC_Payment_Gateway {
  21. public $instructions;
  22. public function __construct() {
  23. $this->id = 'noob_payment';
  24. $this->icon = apply_filters( 'woocommerce_noob_icon', plugins_url('/assets/icon.png', __FILE__ ) );
  25. $this->has_fields = false;
  26. $this->method_title = __( 'Noob Payment', 'noob-pay-woo');
  27. $this->method_description = __( 'Noob local content payment systems.', 'noob-pay-woo');
  28. $this->title = $this->get_option( 'title' );
  29. $this->description = $this->get_option( 'description' );
  30. $this->instructions = $this->get_option( 'instructions' );
  31. $this->init_form_fields();
  32. $this->init_settings();
  33. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
  34. }
  35. public function init_form_fields() {
  36. $this->form_fields = apply_filters( 'woo_noob_pay_fields', array(
  37. 'enabled' => array(
  38. 'title' => __( 'Enable/Disable', 'noob-pay-woo'),
  39. 'type' => 'checkbox',
  40. 'label' => __( 'Enable or Disable Noob Payments', 'noob-pay-woo'),
  41. 'default' => 'no'
  42. ),
  43. 'title' => array(
  44. 'title' => __( 'Noob Payments Gateway', 'noob-pay-woo'),
  45. 'type' => 'text',
  46. 'default' => __( 'Noob Payments Gateway', 'noob-pay-woo'),
  47. 'desc_tip' => true,
  48. 'description' => __( 'Add a new title for the Noob Payments Gateway that customers will see when they are in the checkout page.', 'noob-pay-woo')
  49. ),
  50. 'description' => array(
  51. 'title' => __( 'Noob Payments Gateway Description', 'noob-pay-woo'),
  52. 'type' => 'textarea',
  53. 'default' => __( 'Please remit your payment to the shop to allow for the delivery to be made', 'noob-pay-woo'),
  54. 'desc_tip' => true,
  55. 'description' => __( 'Add a new title for the Noob Payments Gateway that customers will see when they are in the checkout page.', 'noob-pay-woo')
  56. ),
  57. 'instructions' => array(
  58. 'title' => __( 'Instructions', 'noob-pay-woo'),
  59. 'type' => 'textarea',
  60. 'default' => __( 'Default instructions', 'noob-pay-woo'),
  61. 'desc_tip' => true,
  62. 'description' => __( 'Instructions that will be added to the thank you page and odrer email', 'noob-pay-woo')
  63. ),
  64. ) );
  65. }
  66. public function process_payments( $order_id ) {
  67. $order = wc_get_order( $order_id );
  68. // Some other code
  69. }
  70. }
  71. }
  72. }
  73. add_filter( 'woocommerce_payment_gateways', 'add_to_woo_noob_payment_gateway');
  74. function add_to_woo_noob_payment_gateway( $gateways ) {
  75. $gateways[] = 'WC_Noob_pay_Gateway';
  76. return $gateways;
  77. }
  78. add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'woo_noob_payment_gateway_plugin_links' );
  79. function woo_noob_payment_gateway_plugin_links( $links ) {
  80. $plugin_links = array(
  81. '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=noob_payment' ) . '">' . __( 'Configure', 'noob-pay-woo' ) . '</a>'
  82. );
  83. return array_merge( $plugin_links, $links );
  84. }

字符串
现在它应该显示在结帐,启用时.

展开查看全部

相关问题