mollie / WooCommerce

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

Feature Request: Minimum Order Amount Restriction for Klarna Payments #891

Open beljp opened 5 months ago

beljp commented 5 months ago

I propose a feature addition to enable setting minimum order values for specific payment methods, like Klarna. This functionality would allow usuers to manage payment methods on small orders. Currently, the absence of such a feature limits our ability to optimize payment strategies based on order size.

Incorporating a minimum order value requirement for certain payment options could greatly enhance merchant control and financial efficiency. I hope to see this feature considered for implementation to benefit a wide range of Mollie users.

Thank you for your support and commitment to improving the platform.

InpsydeNiklas commented 3 months ago

Hello @beljp, while there is currently no setting to control min/max amounts directly in the Mollie plugin, the availability of payment methods in WooCommerce can be controlled by certain third-party plugins, or with a code snippet like this:

add_filter('woocommerce_available_payment_gateways', function($available_gateways) {
    // Define your minimum and maximum amounts
    $min_amount = 50;
    $max_amount = 500;

    // Define which payment methods should be restricted
    $restricted_payment_methods = array(
        'mollie_wc_gateway_klarnapaylater',
        'mollie_wc_gateway_klarnasliceit',
        'mollie_wc_gateway_klarnapaynow',
        'mollie_wc_gateway_klarna'
    );

    // Get the cart total
    $cart_total = WC()->cart->total;

    // Loop through the restricted payment methods
    foreach ($restricted_payment_methods as $payment_method) {
        if (isset($available_gateways[$payment_method])) {
            // Remove payment method if the cart total is outside the specified range
            if ($cart_total < $min_amount || $cart_total > $max_amount) {
                unset($available_gateways[$payment_method]);
            }
        }
    }

    return $available_gateways;
});

Adding this functionality directly in the plugin is on the roadmap, but it will take a bit more time. I hope this helps you for now.