wordpresswoocommercewordpress-plugin-creation

WooCommerce Plugin: needs_setup not triggering


Prerequisites

Describe the bug

needs_setup is never even used if I override it for my WC_Payment_Gateway_CC payment gateway.

Please, let me know if this is deprecated.


    public function needs_setup(): bool {
        WC_MyGateway_Logger::logg('DEBUG: ' . $this->id . ' ' . $this->plugin_id); // never reached
        return empty($this->get_option('account_id'));
    }

Expected behavior

needs_setup should be triggered if overridden and should show Complete setup like PayPal plugin does, for example.

Actual behavior

Nothing happens.

Steps to reproduce

I am using WooCommerce Version 10.2.0-dev.

WordPress Environment

WordPress Environment

The System Status Report is found in your WordPress admin under WooCommerce > Status. Please select “Get system report”, then “Copy for GitHub”, and then paste it here.

Isolating the problem

I am overridding this public method in my woocommerce payment gateway. However, it is being ignored completely.


Solution

  • It looks like adding is_account_connected in combination with needs_setup did the trick for me. According to this logic here: PaymentGateway.php#L58, needs_setup should evaluate to true whereas is_account_connected needs to evaluate to false.