Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shameemreza/749f7d77127b07fc648e7804b35531a0 to your computer and use it in GitHub Desktop.
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
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