WC_AJAX::variation_bulk_action_variable_sale_schedule
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() WC AJAX::variation bulk action variable sale schedule code WC 10.8.1
private static function variation_bulk_action_variable_sale_schedule( $variations, $data ) {
if ( ! isset( $data['date_from'] ) && ! isset( $data['date_to'] ) ) {
return;
}
foreach ( $variations as $variation_id ) {
$variation = wc_get_product( $variation_id );
if ( 'false' !== $data['date_from'] ) {
$date_on_sale_from = date( 'Y-m-d 00:00:00', strtotime( wc_clean( $data['date_from'] ) ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
$variation->set_date_on_sale_from( $date_on_sale_from );
}
if ( 'false' !== $data['date_to'] ) {
$date_on_sale_to = date( 'Y-m-d 23:59:59', strtotime( wc_clean( $data['date_to'] ) ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
$variation->set_date_on_sale_to( $date_on_sale_to );
}
$variation->save();
}
}