Created
January 7, 2025 09:14
-
-
Save shameemreza/749f7d77127b07fc648e7804b35531a0 to your computer and use it in GitHub Desktop.
Recalculate the order totals (including taxes) for trial subscriptions: https://woocommerce.com/document/subscriptions/develop/action-reference/#payment-and-renewal-actions
This file contains hidden or 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
add_action('woocommerce_scheduled_subscription_payment', 'recalculate_taxes_before_payment', 10, 1); | |
function recalculate_taxes_before_payment($subscription_id) { | |
$subscription = wcs_get_subscription($subscription_id); | |
if ($subscription) { | |
foreach ($subscription->get_related_orders() as $renewal_order_id) { | |
$renewal_order = wc_get_order($renewal_order_id); | |
if ($renewal_order && 'pending' === $renewal_order->get_status()) { | |
// Recalculate totals, including taxes | |
$renewal_order->calculate_totals(); | |
$renewal_order->save(); // Save the updated totals to the order | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment