Custom Payment Gateway does not show in the checkout of block theme
-
I have a custom payment gateway plugin, which works perfectly in a classic theme and that option is shown at checkout, but in block themes it does not work correctly. It is added as a payment method in the WooCommerce section, but the option does not appear at checkout. I’m using the twenty twenty four theme.
This is my code
<?php // add_action('init', function() { add_filter('woocommerce_payment_gateways', 'add_whatsapp_payment_gateway', 99, 1); // }); function add_whatsapp_payment_gateway ($gateways ) { $gateways[] = 'Whatsapp_Payment_Gateway'; return $gateways; } class Whatsapp_Payment_Gateway extends WC_Payment_Gateway { // Constructor for initializing the payment gateway public function __construct() { $this->id = 'whatsapp_payment_gateway'; $this->method_title = __('WhatsApp Checkout', 'cro-wa-payment-gateway'); // title on the admin settings page $this->method_description = __('WhatsApp Checkout', 'cro-wa-payment-gateway'); // Description to show on admin settings page $this->has_fields = true; $this->init_form_fields(); $this->init_settings(); $this->title = $this->get_option('title'); $this->description = $this->get_option('description'); add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); } // Initialize settings fields public function init_form_fields() { $this->form_fields = array( 'title' => array( 'title' => __('Title', 'woocommerce'), 'type' => 'text', 'description' => __('This controls the title displayed during checkout.', 'woocommerce'), 'default' => __('WhatsApp Checkout', 'woocommerce'), 'desc_tip' => true, ), 'description' => array( 'title' => __('Description', 'woocommerce'), 'type' => 'textarea', 'description' => __('This controls the description displayed during checkout.', 'woocommerce'), 'default' => __('Terminá tu compra con nuestros asesores en WhatsApp', 'woocommerce'), ), // Add more fields here // ... ); } // Process payment // public function process_payment($order_id) // { // global $woocommerce; // $order = new WC_Order($order_id); // // Mark as on-hold (we're awaiting the cheque) // $order->update_status('on-hold', __('Awaiting cheque payment', 'woocommerce')); // // Remove cart // $woocommerce->cart->empty_cart(); // // Return thankyou redirect // return array( // 'result' => 'success', // 'redirect' => $this->get_return_url($order) // ); // } // Display payment fields during checkout // public function payment_fields() // { // global $woocommerce; // if ($this->description) { // echo wpautop(wp_kses_post($this->description)); // } // } // Validate payment fields // public function validate_fields() // { // // Validate payment fields submitted by the customer // // ... // } }
I also attach images below
View post on imgur.com
View post on imgur.com
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Custom Payment Gateway does not show in the checkout of block theme’ is closed to new replies.