Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Created March 24, 2020 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plugin-republic/be3d7d933512a7f6b4b5e2e182174b71 to your computer and use it in GitHub Desktop.
Save plugin-republic/be3d7d933512a7f6b4b5e2e182174b71 to your computer and use it in GitHub Desktop.
<?php
/**
* Custom validation to set minimum number of uploads
*/
function prefix_check_minimum_uploads( $passed, $post, $item ) {
// Enter the Group ID for the upload field
$group_id = 2908;
// Enter the Field ID of the upload field
$field_id = 2909;
// Set the minimum number of uploads required
$min_uploads = 3;
// Set your message if the user doesn't upload enough files
$message = 'Please upload 6 files';
$field_name = 'pewc_group_' . $group_id . '_' . $field_id . '_number_uploads';
if( isset( $post[$field_name] ) && floatval( $post[$field_name] ) < $min_uploads ) {
wc_add_notice( $message, 'error' );
$passed = false;
}
return $passed;
}
add_filter( 'pewc_filter_validate_cart_item_status', 'prefix_check_minimum_uploads', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment