SO I was trying to make a custom payment gateway plugin for woocommerce. This code seems alright but when I upload it to my site my site shows "There has been a critical error on this website. Please check your site admin email inbox for instructions."
<?php
/**
* Plugin Name: Custom Bkash Payment for WC
* Plugin URI:
* Description: This plugin helps you to add Bkash store payment link to checkout page.
* Version: 1.0.0
* Author: Classified
* Author URI: https://example.com
* License: GPL-2.0 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: custom-bkash-payment
*/
// Your plugin code goes here.
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters('active_plugins', get_option( 'active_plugins' )))) return;
add_action( 'plugins_loaded', 'custom_bkash-payment_init', 11);
function custom_bkash_payment_init() {
if ( class_exists('WC_Payment_Gateway')) {
class WC_Custom_Bkash_Pay_Gateway extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'custom_payment';
$this->icon = apply_filters( 'woocommerce_custom_bkash_payment_icon', plugins_url( '/assets/icon.png' , __FILE__ ));
$this->has_fields = false;
$this->method_title = __( 'bKash Payment', 'custom-bkash-payment');
$this->method_description = __( 'bKash Payment System.', 'custom-bkash-payment');
$this->init_form_fields();
$this->init_settings();
}
public function init_form_fields() {
$this->form_fields = apply_filters( 'woo_custom_bkash_pay_fields', array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'custom-bkash-payment'),
),
));
}
}
}
}
I've tried to ask ChatGPT. But ChatGPT responded that there was no problem with the code.
You seem to have hooked your function incorrectly:
add_action( 'plugins_loaded', 'custom_bkash-payment_init', 11);
You may have meant to pass custom_bkash_payment_init
not custom_bkash-payment_init
as the second parameter (there should be an underscore, _
, between bkash
and payment
, not a dash, -
):
add_action( 'plugins_loaded', 'custom_bkash_payment_init', 11 );