Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created March 28, 2023 17:53
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 kartikparmar/bf192da803843d2e2320f5afd5661d24 to your computer and use it in GitHub Desktop.
Save kartikparmar/bf192da803843d2e2320f5afd5661d24 to your computer and use it in GitHub Desktop.
Changing the product price in the renewal order.
<?php
add_filter( 'wcs_renewal_order_created', 'test_change_renewal_order_price', 10, 2 );
function test_change_renewal_order_price( $renewal_order, $subscription ) {
// Get the line item for the subscription product
$line_items = $renewal_order->get_items();
foreach( $line_items as $line_item ) {
// Set the new price
$new_price = 19.99;
// Update the line item price and total
$line_item->set_subtotal( $new_price );
$line_item->set_total( $new_price );
}
// Recalculate the order totals
$renewal_order->calculate_totals();
return $renewal_order;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment