Created
January 2, 2024 12:45
-
-
Save goranefbl/06d574bd3ff2158a364ae2897b88bbb0 to your computer and use it in GitHub Desktop.
Prevent WooCommerce Subscriptions renewal coupons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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