Reputation: 11
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;
}
Upvotes: 1
Views: 1803
Reputation: 51
This is a bit late but there has been no reply.
If you take a look at 'wcs_create_order_from_subscription()'
This the function where the new order is created. here also has a different filter that isn't mentioned within the documentation 'wcs_new_order_created'.
So here is what your code should be.
function gens_renewal_order_created($order, $subscription){
$order = new WC_Order( $order->id );
$order->set_total($order->get_total() - 5);
return $order;
}
add_filter('wcs_new_order_created','gens_renewal_order_created', 10, 2 );
Upvotes: 5