Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created January 2, 2024 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goranefbl/06d574bd3ff2158a364ae2897b88bbb0 to your computer and use it in GitHub Desktop.
Save goranefbl/06d574bd3ff2158a364ae2897b88bbb0 to your computer and use it in GitHub Desktop.
Prevent WooCommerce Subscriptions renewal coupons
<?php
// Made by Goran from https://wpgens.com
add_action( 'wcs_renewal_order_created', 'remove_discount_from_renewal', 10, 2 );
function remove_discount_from_renewal( $renewal_order, $subscription ) {
// Check if there is a specific coupon applied that you want to remove
foreach ( $renewal_order->get_items('coupon') as $item_id => $item ) {
if ( 'specific_coupon_code' === $item->get_code() ) {
// Remove the coupon
$renewal_order->remove_coupon( $item->get_code() );
// Optionally, adjust the total if needed
$renewal_order->calculate_totals();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment