I have a custom payment gateway that acts as a digital "wallet" for my site. Users can purchase "credits" that go into the wallet. Then they can use the wallet for other purchases throughout the site. Works great. When they have credits and use that payment option, it calls my custom gateway process_payment api, I deduct the credits, and complete the order. The only catch is that the order appears to have been paid "by cash" as far as woo is concerned. So, it shows up in Revenue totals. But it is not new revenue - that happened when the credits were originally purchased.
So, I want to add something that will prevent this order from being included in the revenue totals. I have tried setting the order total to 0. That does keep it out of the revenue, but the order will not allow the payment method to be set to my payment gateway, which is nice to have in the post checkout order details (i.e. want it to say "Payment method: Credits". I think if the order total is $0, then woo won't allow the payment method to be set at all. I have tried to work with the subtotal, but no way to change that except in the WC_Cart, which doesn't affect the order at this late stage of process_payment. I have set the discount_total, but that doesn't appear to affect the order total. I can't set the order total after $order->payment_complete() is called. My current gateway API for reference
class WC_Gateway_Credits extends WC_Payment_Gateway {
...
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
// subtract the credits
$user_id = $order->get_user_id();
Subscriber::get_instance($user_id)->credits_used($order_id, $order->get_total());
// works but doesn't allow payment method:
// $order->set_total(0.00);
// doesn't work:
// $order->set_payment_method($this->id);
$order->payment_complete();
// Remove cart
WC()->cart->empty_cart();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}