mollie / WooCommerce

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

Feature Request: Country Based Payment Methods #218

Closed f3bruary closed 6 years ago

f3bruary commented 6 years ago

I would like the request the following feature to be implemented.

Base the available payment methods in the front-end checkout on the billing/shipping country.

This way my Belgian customers see Belgian payment methods like Belfius, KBC, Bancontact, etc.

And my Dutch customers only see iDeal, etc.

It doesn't make sense to show unsupported payment methods and it crowds the front-end.

Right now I use the following snippet to accomplish this but it would be nice if the plugin could officially support it.

/**
 * @snippet       WooCommerce Disable Payment Gateway for a Specific Country
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=164
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.3.1
 */

function payment_gateway_disable_country( $available_gateways ) {
    global $woocommerce;
    if ( is_admin() ) return;
    if ( isset( $available_gateways['mollie_wc_gateway_ideal'] ) && $woocommerce->customer->get_billing_country() == 'BE' ) {
        unset( $available_gateways['mollie_wc_gateway_ideal'] );
    } elseif ( $woocommerce->customer->get_billing_country() == 'NL' ) {
        unset( $available_gateways['mollie_wc_gateway_belfius'] );
                unset( $available_gateways['mollie_wc_gateway_mistercash'] );
        unset( $available_gateways['mollie_wc_gateway_kbc'] );
    }
    return $available_gateways;
}

add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
willemstuursma commented 6 years ago

There are no plugins that support this?

f3bruary commented 6 years ago

I've found one plugin but it hasn't been updated in over a year and there have been some significant changes in both WP and WC since then, so I don't really feel comfortable using it.

It's just a request. If you deem it unnecessary, then no worries, I'll always have the above code to use.

davdebcom commented 6 years ago

@f3bruary We've discussed this in the past https://github.com/mollie/WooCommerce/issues/63

I would suggest trying this plugin, when I tested it less then 3 months ago, it worked perfectly. https://wordpress.org/plugins/woocommerce-country-based-payments/

willemstuursma commented 6 years ago

@davdebcom is it in the FAQ / wiki's you created?

davdebcom commented 6 years ago

@willemstuursma No that's another one 'Can I add payment fees to payment methods?' https://wordpress.org/plugins/mollie-payments-for-woocommerce/

But I'll also add this to the FAQ!