Last active
August 19, 2022 20:00
-
-
Save primathon/c23bcf0cb8655f646fc2bab2ee9d3434 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Allow third-parties to filter whether the customer can renew a subscription early. | |
* | |
* @since 2.3.0 | |
* | |
* @param bool $can_renew_early Whether early renewal is permitted. | |
* @param WC_Subscription $subscription The subscription being renewed early. | |
* @param int $user_id The user's ID. | |
* @param string $reason The reason why the subscription cannot be renewed early. Empty | |
* string if the subscription can be renewed early. | |
*/ | |
function mx_override_subscription_early_renewal_rules($can_renew_early, $subscription, $user_id, $reason) | |
{ | |
// Example subscription product ID that is NOT auto-renewing (or anything else in this list:) | |
// https://woocommerce.com/document/early-renewal/#section-3 | |
$MY_PRODUCT_ID = 12345; | |
// What items does this subscription have? | |
foreach($subscription->get_items() as $item_id => $item_data) | |
{ | |
// This subscription contains the product I want to allow early renewal for | |
if ($item_data->get_product_id() == $MY_PRODUCT_ID) | |
{ | |
// Allow early renewal | |
$can_renew_early = true; | |
} | |
} | |
return $can_renew_early; | |
} | |
add_filter('woocommerce_subscriptions_can_user_renew_early', 'mx_override_subscription_early_renewal_rules', 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment