• Resolved parsec1

    (@parsec1)


    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)
  • Saif

    (@babylon1999)

    Hello @parsec1,

    Thank you for reaching out!

    WooCommerce blocks are triggered by the same hooks in theme templates (they’re mostly JS-based). :?)

    Our team has published a detailed blog post on creating dummy payment methods with blocks. I highly recommend checking it out at this link.

    Also, just a small reminder that we’re not able to provide support for customization requests per our support policy. If you require the assistance of a developer, consider hiring a WooExpert. :?)

    Let us know if you have any other questions!

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.