• Resolved zavmo

    (@zavmo)


    Hello.
    Is it possible to remove product images when deleting a product?
    I know that woocommerce doesn’t have this functionality. But at woocommerce, we work with the store ourselves, and we can track these things. In a multi-user store, this can be a problem.

    • The image is not tied to a specific product.
    • We can’t clear files and database in bulk (hello woocommerce)
    • Yes, the user has his own library of files, but how to make him keep it clean.
      I don’t know how difficult it is. But you need to either delete the images when deleting the product. Or limit the user to a certain storage size. This function is already implemented in one of the marketplace plugins. Plus it allows you to force the user to upload smaller images.
Viewing 1 replies (of 1 total)
  • Plugin Author WebWizards

    (@webwizardsdev)

    Hi there,

    With MarketKing, it’s possible to restrict the file size allowed for each image or file. By default that limit is set to 1MB, but you can modify it by adding this PHP code snippet to your site:

    add_filter('marketking_vendor_upload_file_size', function($size){
    	return 1048576;
    }, 10, 1);

    That number represents 1 MB in bytes. You can for example replace it with 104857 to set the limit to 100KB.

    To make the plugin automatically remove product images when the products are deleted by a vendor, you can add this PHP code snippet to your site:

    add_action('wp_trash_post', function($post_id){
            
        $product = wc_get_product( $post_id );
    
        if ( !$product ) {
            return;
        }
    
        $featured_image_id = $product->get_image_id();
        $image_galleries_id = $product->get_gallery_image_ids();
    
        if( !empty( $featured_image_id ) ) {
            wp_delete_post( $featured_image_id );
        }
    
        if( !empty( $image_galleries_id ) ) {
            foreach( $image_galleries_id as $single_image_id ) {
                wp_delete_post( $single_image_id );
            }
        }
        
    }, 10, 1);

    These snippets can be added to the functions.php file of your child theme.

Viewing 1 replies (of 1 total)
  • The topic ‘Remove product images’ is closed to new replies.