Don’t allow to switch payment method for unpaid order
The rule is that if you pay with paypal or credit card you get -5%.
A customer tried to pay with card, it wasn’t successful and after that he paid with cash on delivery, but he get the discount.
We can’t recalculate existing order, but it’s possible to force payment method.
Please, use this PHP code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
add_action('before_woocommerce_pay', function() { $order_key = isset( $_GET['key'] ) ? $_GET['key'] : null; if ( ! $order_key ) { return; } $order_id = wc_get_order_id_by_order_key( $order_key ); $order_id = absint( $order_id ); $order = wc_get_order($order_id); if ( ! $order ) { return; } $payment_method = $order->get_payment_method(); add_filter( 'woocommerce_available_payment_gateways', function ( $gateways ) use ( $payment_method ) { return isset( $gateways[ $payment_method ] ) ? array( $payment_method => $gateways[ $payment_method ] ) : array(); }, 10, 1 ); }); |