Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Purge Orders

// Scheduled Action Hook
function order_purge( $param1 = '$shop_dir_path' ) {
	// Deletes .sql.gz files older than 1 hour.
	//$files=array_map('unlink', glob(dirname(PRNSRV_ROOT) . PRNSRV_ORDER_PATH . "/{ho/*/*/response/*,bb/*/*/response/*}",GLOB_BRACE)); 
	$files = array_map('prnsrv_delete_orders', glob($shop_dir_path['response'] . "/*"));
	function prnsrv_delete_orders($file){
	        //foreach($files as $file) { //file check
	            if(is_file($file) && time() - filemtime($file) >= 60*60 /* 1 hour */) {
	                
	                unlink($file);
	        //}
	    }
	    
	}
}

// Custom Cron Recurrences
function order_purge_daily_recurrence( $schedules ) {
	$schedules['2hours'] = array(
		'display' => __( 'Every 2 hours', 'textdomain' ),
		'interval' => 7200,
	);
	return $schedules;
}
add_filter( 'cron_schedules', 'order_purge_daily_recurrence' );

// Schedule Cron Job Event
function order_purge_daily() {
	if ( ! wp_next_scheduled( 'order_purge' ) ) {
		wp_schedule_event( current_time( 'timestamp' ), '2hours', 'order_purge', array( '$shop_dir_path' ) );
	}
}
add_action( 'wp', 'order_purge_daily' );