mollie / WooCommerce

Official Mollie extension for WooCommerce
https://wordpress.org/plugins/mollie-payments-for-woocommerce/
Other
130 stars 52 forks source link

Disable Mister Cash payment gateway by default #302

Closed gijshendriksen closed 4 years ago

gijshendriksen commented 5 years ago

The Mister Cash payment gateway is no longer in use, but the payment gateway still exists and has an enabled status of 'yes'. However, as far as I can tell it's not really possible or easy to disable it somehow, as it is no longer listed in the payment settings and there is no entry for it in the wp_options table either.

This becomes an issue when one wants to make a list of all available and enabled payments in their shop. For instance, take the following code:

$gateways = WC()->payment_gateways()->get_available_payment_gateways();
foreach ($gateways as $key => $gateway) {
    if (wc_string_to_bool($gateway->enabled)) {
        echo $key . ', ' . $gateway->title . '<br />';
    }
}

results in the following output (in one specific shop):

mollie_wc_gateway_ideal, iDEAL
mollie_wc_gateway_creditcard, Credit card
bacs, Direct bank transfer
cod, Cash on delivery
mollie_wc_gateway_mistercash, Bancontact

Maybe I'm missing or skipping a hook somewhere using which it is removed from the list of available gateways, but I couldn't really find any. So, is it possible/desirable to set the enabled status of Mister Cash to 'no' by default? For instance by adding public $enabled = 'no'; to Mollie_WC_Gateway_MisterCash.

I'd love to hear your thoughts on this!

widoz commented 5 years ago

@gijshendriksen You can filter the gateways by using the filter woocommerce_payment_gateways.

Mollie has an hook for that add_filter( 'woocommerce_payment_gateways', array ( __CLASS__, 'addGateways' ) ); which the priority is 10.

You can create a new one with priority 11 so it's executed after the mollie filter and remove the gateways you don't want to allow in your project.

add_filter('woocommerce_payment_gateways', function(array $gateways) {

    $index = array_search('Mollie_WC_Gateway_MisterCash', $gateways, true);
    if ($index !== false) {
        unset($gateways[$index]);
    }

    return $gateways;
});

I found various places where the gateway is removed. First of all it is removed from the admin settings (see https://github.com/mollie/WooCommerce/blob/master/mollie-payments-for-woocommerce/includes/mollie/wc/plugin.php#L400) then it is removed from the settings view (see https://github.com/mollie/WooCommerce/blob/master/mollie-payments-for-woocommerce/includes/mollie/wc/helper/settings.php#L240) and from the frontend checkout (see https://github.com/mollie/WooCommerce/blob/master/mollie-payments-for-woocommerce/includes/mollie/wc/plugin.php#L857).

I noticed also there's a line of code that remove the option from the bancontact (see https://github.com/mollie/WooCommerce/blob/master/mollie-payments-for-woocommerce/includes/mollie/wc/gateway/bancontact.php#L16-L20).

I don't know why was not removed entirely so I need to investigate and in case make sense to completely remove the gateway but we have to take into account BC changes.

widoz commented 5 years ago

Asking to @ndijkstra about Mister cash and he said the gateway was kept to be able to view order that were paid with that gateway.

I think we could add a conditional statement to remove it also in the frontend if we need it just to see the order paid with Mister cash.

mmaymo commented 4 years ago

Closed because of inactivity