Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rajeshsingh520/9e6c4cba74ca557bfa65db34166430cd to your computer and use it in GitHub Desktop.

Select an option

Save rajeshsingh520/9e6c4cba74ca557bfa65db34166430cd to your computer and use it in GitHub Desktop.
This halves the shipping cost in the renewal order of the woocommerce subscription
add_action( 'wcs_renewal_order_created', 'pi_modify_renewal_shipping', 10, 2 );
function pi_modify_renewal_shipping( $renewal_order, $subscription ) {
foreach ( $renewal_order->get_items( 'shipping' ) as $item_id => $shipping_item ) {
$total = (float) $shipping_item->get_total();
$new_total = $total / 2;
$shipping_item->set_total( $new_total );
$shipping_item->save();
}
$renewal_order->calculate_totals( false );
$renewal_order->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment