Reputation: 93
Is there any plugin to limit the number of images uploaded to a woo-commerce product
I have gone through different plugins but didn't find any that meets my requirement.
Upvotes: 1
Views: 654
Reputation: 507
You can set limit to post for max attachments.
add_filter('wp_handle_upload_prefilter', 'limit_wp_handle_upload_prefilter');
function yoursite_wp_handle_upload_prefilter($file) {
// This bit is for the flash uploader
if ($file['type']=='application/octet-stream' && isset($file['tmp_name'])) {
$file_size = getimagesize($file['tmp_name']);
if (isset($file_size['error']) && $file_size['error']!=0) {
$file['error'] = "Unexpected Error: {$file_size['error']}";
return $file;
} else {
$file['type'] = $file_size['mime'];
}
}
if ($post_id = (isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : false)) {
if (count(get_posts("post_type=attachment&post_parent={$post_id}"))>4)
$file['error'] = "Sorry, you cannot upload more than four (5) image.";
}
return $file;
}
Upvotes: 0