WC_AJAX::variation_bulk_action_variable_sale_scheduleprivate staticWC 1.0

Bulk action - Sale Schedule.

Method of the class: WC_AJAX{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_AJAX::variation_bulk_action_variable_sale_schedule( $variations, $data );
$variations(array) (required)
List of variations.
$data(array) (required)
Data to set.

WC_AJAX::variation_bulk_action_variable_sale_schedule() code WC 11.0.1

private static function variation_bulk_action_variable_sale_schedule( $variations, $data ) {
	if ( ! isset( $data['date_from'] ) && ! isset( $data['date_to'] ) ) {
		return;
	}

	$date_from = isset( $data['date_from'] ) ? wc_clean( $data['date_from'] ) : false;
	$date_to   = isset( $data['date_to'] ) ? wc_clean( $data['date_to'] ) : false;

	foreach ( $variations as $variation_id ) {
		$variation = wc_get_product( $variation_id );

		if ( false !== $date_from && 'false' !== $date_from ) {
			$date_on_sale_from = '' === $date_from ? null : date( 'Y-m-d 00:00:00', strtotime( $date_from ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
			$variation->set_date_on_sale_from( $date_on_sale_from );
		}

		if ( false !== $date_to && 'false' !== $date_to ) {
			$date_on_sale_to = '' === $date_to ? null : date( 'Y-m-d 23:59:59', strtotime( $date_to ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
			$variation->set_date_on_sale_to( $date_on_sale_to );
		}

		$variation->save();
	}
}