Documentation > Developers > Filter Examples > Automatically Close Collection After the Last Client Has Approved Their Selection

Automatically Close Collection After the Last Client Has Approved Their Selection

/**
 * Automatically close collection after the last client has approved their selection
 */
function my_picu_maybe_close_collection( $collection_id, $ident ) {
	$all_approved = true;

	$clients = get_post_meta( $collection_id, '_picu_collection_hashes', true );

	foreach( $clients as $ident => $client ) {
		if ( $client['status'] != 'approved' ) {
			$all_approved = false;
		}
	}

	if ( $all_approved ) {
		wp_update_post( [
			'ID' => $collection_id,
			'post_status' => 'approved'
		] );

		if ( function_exists( 'picu_update_collection_history' ) ) {
			picu_update_collection_history( $collection_id, 'approved' );
		}
	}
}

add_action( 'picu_after_approval', 'my_picu_maybe_close_collection', 10, 2 );Code language: PHP (php)

Need help?

If you couldn’t find what you were looking for and need more assistance, please get in touch with us directly and we’re happy to help.