You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调整并同步WooCommerce订阅至自定义日期:周三/周四订单首期交付日期修正后的字段一致性问题

WooCommerce Subscriptions: Align Start Date & Ensure Future Renewals for Late-Week Orders

Let me break down what you need to fix the mismatched dates and confirm future renewal alignment based on your setup:

Why Your Current Setup Isn't Updating All Fields

The woocommerce_subscriptions_product_first_renewal_payment_time hook only adjusts the first renewal payment/delivery date—it doesn't touch the subscription's core start_date metadata. That's why your dashboard's "Start Date" and confirmation email still show the original order date, even though "Next Delivery" is correct.

Key Fields/Areas to Update

To fully align the subscription to the next Thursday for Wednesday/Thursday orders, you need to address three things:

  • The subscription's internal start_date (controls dashboard display and future renewal calculations)
  • The "Start Date" shown in order confirmation emails
  • Sync the first payment date with the new start date to avoid conflicts

Updated Code Solution

Add these snippets to your functions.php (you can adjust or remove your original hook based on the notes below):

1. Adjust Subscription Start Date & First Payment Date

This hook fires right after a subscription is created, updating its core start date to next Thursday for qualifying orders:

function rem_adjust_subscription_start_date( $subscription, $order, $product_id ) {
    // Match timezone to your WooCommerce settings
    date_default_timezone_set( get_option('timezone_string') );
    $current_day = date('D');

    // Check if order was placed on Wednesday or Thursday
    if ( $current_day === 'Wed' || $current_day === 'Thu' ) {
        $new_start_timestamp = strtotime('Thursday next week');
        $new_start_date = date('Y-m-d H:i:s', $new_start_timestamp);

        // Update subscription's core start date
        $subscription->update_meta_data( '_start_date', $new_start_date );
        // Sync first payment date to match the new start date
        $subscription->update_meta_data( '_first_payment_date', $new_start_date );
        $subscription->save();
    }
}
add_action( 'woocommerce_subscriptions_after_create_subscription', 'rem_adjust_subscription_start_date', 10, 3 );

2. Fix Start Date in Confirmation Emails

This filter overrides the "Start Date" displayed in subscription confirmation emails:

function rem_adjust_email_start_date( $displayed_start_date, $subscription ) {
    date_default_timezone_set( get_option('timezone_string') );
    $current_day = date('D');

    if ( $current_day === 'Wed' || $current_day === 'Thu' ) {
        $new_start_timestamp = strtotime('Thursday next week');
        return date_i18n( wc_date_format(), $new_start_timestamp );
    }
    return $displayed_start_date;
}
add_filter( 'woocommerce_subscriptions_email_order_meta_start_date', 'rem_adjust_email_start_date', 10, 2 );

About Your Original Renewal Hook

Since we're setting the start_date to next Thursday, WooCommerce Subscriptions will automatically calculate the first renewal date based on your product's subscription period (2/3/4 weeks) plus your "Align Subscription Renewal Day" setting (already set to Thursday). You can either:

  • Remove your original woocommerce_subscriptions_product_first_renewal_payment_time hook to avoid conflicts, or
  • Adjust its logic to reference the subscription's start_date instead of the current day

Verifying Future Renewals

To confirm everything works as expected:

  1. Place a test order on Wednesday/Thursday
  2. Navigate to the subscription dashboard and check the Renewal Schedule section
  3. All future renewal dates should land on Thursday, spaced correctly according to your product's period (e.g., every 4 weeks from the new start date)

This setup ensures the entire subscription lifecycle is aligned to your required delivery schedule, with no mismatched dates in dashboards or emails.

内容的提问来源于stack exchange,提问作者armadadrive

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 15:07:50