Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Joel

Date Time for Subscription’s Next Scheduled Date should auto-confirm on click

No one ever wants or needs to change the time, and if they want to do it they can do so before selecting the data. The “date” and not “date_time” is the perfect date chooser, and this is how it used to work. This is an easy change that would help me out a lot, if not, please provide us with new filters for custom field saving to use so I can just do a custom field for “scheduled_next_date” and save it properly.

2 years, 6 months ago
Stefan van den Dungen Gronovius
Developer

The next payment date requires a DateTime, and when looking at the codebase of the WooCommerce integration, we did not change this recently. I understand that in many cases it will be faster to just set the date, but I’m not sure if changing it now is the right way. We already have some hooks that you can use to change the field type and save the value. If you use a hook to change the DateTime field to a date field for this WC column, you also need to change the save value just before it is saved, because WC throws an error when the date is not a date with time. The following snippet will change the field to a date field and saved the correct value:

add_filter( 'acp/editing/view_settings', function ( $view, AC\Column $column ) {
	if ( $column instanceof ACA\WC\Column\ShopSubscription\NextPaymentDate ) {
		$view['type'] = 'date';
	}

	return $view;
}, 10, 2 );

add_filter( 'acp/editing/save_value', function ( $value, AC\Column $column, $id ) {
	if ( $value && $column instanceof ACA\WC\Column\ShopSubscription\NextPaymentDate ) {
		// Add time to the date so that WC can store the date correctly
		$currentDate = $column->get_raw_value( $id );
		$dateTime = DateTime::createFromFormat( 'Y-m-d H:i:s', $currentDate );

		$value .= $dateTime !== false ? $dateTime->format( 'H:i:s' ) : '00:00:00';
	}

	return $value;
}, 10, 3 );

2 years, 6 months ago

You must be logged in to reply to this topic.