I face a problem with showing a custom payment option in payment options
Iam sure it is set up correctly but it doesn’t appear (like photos)
I also added a js file with some logs to make sure it is working and it did the logs
`<?php
/*
Plugin Name: My Custom Payment Gateway
Description: A custom payment gateway for WooCommerce.
Version: 1.0
Author: Your Name
*/
// Ensure WooCommerce is active
if (in_array(‘woocommerce/woocommerce.php’, apply_filters(‘active_plugins’, get_option(‘active_plugins’)))) {
// Add custom payment gateway class
add_action(‘plugins_loaded’, ‘my_custom_payment_gateway_init’, 5);
function my_custom_payment_gateway_init() {
class WC_Gateway_Custom extends WC_Payment_Gateway {
public function __construct() {
$this->id = ‘custom_gateway’;
$this->icon = ”; // URL to an icon if you want to add
$this->has_fields = true;
$this->method_title = __(‘Custom Gateway’, ‘woocommerce’);
$this->method_description = __(‘Description of custom payment gateway’, ‘woocommerce’);
// Load the settings
$this->init_form_fields();
$this->init_settings();
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
// Save settings
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
}
// Admin options
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __('Enable/Disable', 'woocommerce'),
'type' => 'checkbox',
'label' => __('Enable Custom Payment Gateway', 'woocommerce'),
'default' => 'yes'
),
'title' => array(
'title' => __('Title', 'woocommerce'),
'type' => 'text',
'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'),
'default' => __('Custom Payment', 'woocommerce'),
'desc_tip' => true,
),
'description' => array(
'title' => __('Description', 'woocommerce'),
'type' => 'textarea',
'description' => __('This controls the description which the user sees during checkout.', 'woocommerce'),
'default' => __('Pay using our custom payment gateway.', 'woocommerce')
)
);
}
// Display custom fields on the checkout page
public function payment_fields() {
// Description of the payment method
if ($this->description) {
echo wpautop(wp_kses_post($this->description));
}
// Add custom fields here
?>
<fieldset>
<p class="form-row form-row-wide">
<label for="<?php echo esc_attr($this->id); ?>-custom-field"><?php esc_html_e('Custom Field', 'woocommerce'); ?> <span class="required">*</span></label>
<input id="<?php echo esc_attr($this->id); ?>-custom-field" class="input-text" type="text" autocomplete="off">
</p>
</fieldset>
<?php
}
// Payment processing
public function process_payment($order_id) {
$order = wc_get_order($order_id);
// Mark as on-hold (we're awaiting the payment)
$order->update_status('on-hold', __('Awaiting custom payment', 'woocommerce'));
// Reduce stock levels
wc_reduce_stock_levels($order_id);
// Remove cart
WC()->cart->empty_cart();
// Return thank you page redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url($order)
);
}
}
}
// Add to WooCommerce
add_filter('woocommerce_payment_gateways', 'add_my_custom_payment_gateway');
function add_my_custom_payment_gateway($gateways) {
$gateways[] = 'WC_Gateway_Custom';
return $gateways;
}
// Enqueue JavaScript file
add_action('wp_enqueue_scripts', 'custom_gateway_enqueue_script');
function custom_gateway_enqueue_script() {
wp_enqueue_script('custom-gateway-js', plugin_dir_url(__FILE__) . 'custom-gateway.js', array('jquery'), '1.0', true);
}
}
?>`
I watched alot of videos and tutorials but none of help (iam runing it locally if this help)