Woocomerce subscription : apply coupon for renewal orders

I want to apply a coupon when a renewal order for a subscription is created.
I use stripe as payment gateway for woocommerce subscription.

I found the filter ‘wcs_renewal_order_created’ from the docs : https://docs.woocommerce.com/document/subscriptions/develop/filter-reference/

I manage to apply it, it’s well trigger and I can apply a coupon to this order.
The order amount is reduce by the amount of the coupon.

Problem: Stripe charges the full amount of the order, without the discount. It’s just like if the order I changed was not used by Stripe.

Here is the code sample, that reduce by 5 any renewal order :

function gens_renewal_order_created($order, $subscription){         
    $order = new WC_Order( $order->id );                
    $order->set_total($order->get_total() - 5);     
    return $order;
}

Read more here: Woocomerce subscription : apply coupon for renewal orders

Leave a Reply

Your email address will not be published. Required fields are marked *