This may be helpful for someone. If you want to change the subscription's next payment date for a specific product, then follow this code:
add_action( 'woocommerce_checkout_subscription_created', 'sw_custom_subscriptions_next_payment', 10, 3);
function sw_custom_subscriptions_next_payment( $subscription, $order, $recurring_cart ) {
$order_items = $subscription->get_items();
$product_id = [];
// Loop through order items
foreach ( $order_items as $item_id => $item ) {
// To get the subscription variable product ID and simple subscription product ID
$product_id[] = $item->get_product_id();
}
if ( in_array( 7856, $product_id ) ) {
$new_dates = array(
'next_payment' => date( 'Y-m-d H:i:s', strtotime( '+3 years', time() ) )
);
$subscription->update_dates($new_dates, 'site');
}
}
Reference: https://stackoverflow.com/a/67420195/8498688
To change the first renewal date on Cart and checkout pages, follow the below steps:
1- Remove the native filter hook
// Remove WCS native subscription first renewal date callback from cart/order totals on checkout page
remove_filter( 'wcs_cart_totals_order_total_html', 'wcs_add_cart_first_renewal_payment_date');
2- Add custom callback
add_filter( 'wcs_cart_totals_order_total_html', 'sw_add_cart_first_renewal_payment_date', 10, 2 );
function sw_add_cart_first_renewal_payment_date( $order_total_html, $cart ) {
if ( 0 !== $cart->next_payment_date ) {
$product_id = [];
foreach( $cart->get_cart() as $key => $cart_item ){
$product_id[] = $cart_item['product_id'];
}
if ( in_array( TRIENNUAL_SUBSCRIPTION_PRODUCT_ID, $product_id ) ) {
$first_renewal_date = date_i18n( wc_date_format(), wcs_date_to_time( '+3 years' ) );
} else {
$first_renewal_date = date_i18n( wc_date_format(), wcs_date_to_time( get_date_from_gmt( $cart->next_payment_date ) ) );
}
// translators: placeholder is a date
$order_total_html .= '<div class="first-payment-date"><small>' . sprintf( __( 'First renewal: %s', 'woocommerce-subscriptions' ), $first_renewal_date ) . '</small></div>';
}
return $order_total_html;
}