Created
March 28, 2023 17:53
-
-
Save kartikparmar/bf192da803843d2e2320f5afd5661d24 to your computer and use it in GitHub Desktop.
Changing the product price in the renewal order.
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 | |
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