1

I have Woo-commerce installed I have Woo-commerce subscriptions installed I have Woo-commerce stripe checkout installed.

I go through the checkout procedure and and I get the error "Subscription start date must be before the current day"

enter image description here

I have went through all the settings and I can't see any option where I can set a start date, it is meant to start when the subscription starts.

I've reinstalled everything and insalled everything but I keep getting the same error.

here is a copy of my configuration.

enter image description here

I've tried googling everything but I can't see this error ever before.

I've tried changing the UTC clock in the Dashboard->Settings->General but I still get the same error.

Here is the offending code

   function wcs_create_subscription( $args = array() ) {

$order = ( isset( $args['order_id'] ) ) ? wc_get_order( $args['order_id'] ) : null;

$default_args = array(
    'status'             => '',
    'order_id'           => 0,
    'customer_note'      => null,
    'customer_id'        => ( ! empty( $order ) ) ? $order->get_user_id() : null,
    'start_date'         => ( ! empty( $order ) ) ? $order->order_date : current_time( 'mysql', true ),
    'created_via'        => ( ! empty( $order ) ) ? $order->created_via : '',
    'order_version'      => ( ! empty( $order ) ) ? $order->order_version : WC_VERSION,
    'currency'           => ( ! empty( $order ) ) ? $order->order_currency : get_woocommerce_currency(),
    'prices_include_tax' => ( ! empty( $order ) ) ? ( ( $order->prices_include_tax ) ? 'yes' : 'no' ) : get_option( 'woocommerce_prices_include_tax' ),
);

$args              = wp_parse_args( $args, $default_args );
$subscription_data = array();

// validate the start_date field
if ( ! is_string( $args['start_date'] ) || false === wcs_is_datetime_mysql_format( $args['start_date'] ) ) {
    return new WP_Error( 'woocommerce_subscription_invalid_start_date_format', __( 'Invalid date. The date must be a string and of the format: "Y-m-d H:i:s".', 'woocommerce-subscriptions' ) );
} else if ( strtotime( $args['start_date'] ) > current_time( 'timestamp', true ) ) {
    return new WP_Error( 'woocommerce_subscription_invalid_start_date', __( 'Subscription start date must be before current day', 'woocommerce-subscriptions' ) );
}
JohnnyQ
  • 484
  • 10
  • 23
  • It seems like you should probably contact Woo support for this. I know the team is rolling out fixes for Subs 2.0 as fast as possible. – helgatheviking Oct 21 '15 at 21:26

2 Answers2

1

until this is patched change this line (line 119 for me)

} else if ( strtotime( $args['start_date'] ) > current_time( 'timestamp', true ) ) {

to this

} else if ( strtotime( $args['start_date'].' UTC' ) > current_time( 'timestamp', true ) ) {

The value of $order->order_date from a Woo Commerce class did not contain a timezone format so when this time was compared with the function current_time, the value contained a future date from my servers current time zone.

Dan Kinchen
  • 117
  • 1
  • 8
  • Thanks a lot for this, I've been checking all the updates but they haven't covered this yet. This workaround seems to do the trick. – JohnnyQ Oct 27 '15 at 11:59
  • todays update contains the fix. 2015.10.27 - version 2.0.3 * Fix: use of start date in based on current GMT/UTC offset instead of GMT/UTC offset at the time the subscription was created to handle daylight savings time and changes to a site's timezone – Dan Kinchen Oct 27 '15 at 14:45
  • Sorry this update did not fix this. Although you can clearly see that someone made an attempt to do so. But my fix of adding a timezone of UTC did. So please look on line 125 as of update 2.0.3 – Dan Kinchen Oct 27 '15 at 19:40
  • this makes it work, but the subscriptions all say they'll be active "In 6 hours" due to the fact that I'm in Central Time. Trying to solve this now. – Rebecca Dessonville Jan 26 '16 at 18:28
  • so if I change the WP General timezone setting to UTC-6 (Central) subscriptions work correctly without changing any code. Seems WooCommerce has an issue with City based timezones (America/Chicago) – Rebecca Dessonville Jan 26 '16 at 18:55
  • I opened an issue in the WC Github: https://github.com/woothemes/woocommerce/issues/10179 – Rebecca Dessonville Jan 26 '16 at 19:06
  • If you are having this issue, you most likely have code running on your site that is calling `date_default_timezone_set()` to set PHP's timezone to something other than `UTC`. This is bad and needs to be fixes. It will cause all sorts of problems with anything working in time on your site (including dates on WordPress posts, WooCommerce orders, Subscriptions' payments etc.). The above suggestion is only a bandaid for a serious underlying problem that needs to be addressed directly by removing the use of `date_default_timezone_set()`. – Brent Shepherd Jan 28 '16 at 04:54
0

In Wordpress general settings change your time to UTC(+or-#)to equal your current time and it should fix the problem. At least it did for me just now...