Add Info Alerts for Bad Product Image Uploads

One of the biggest frustrations with a Multivendor site is that you can’t control every aspect of the product listings directly. So if your site uses square images like mine does, but your vendors all take vertical pictures of their items with their iphones, this snippet will show an alert if the image is too small or doesn’t meet appropriate dimensions.

Note that WCMp has provided a series of snippets that look like they do a similar function, but they actually block saving of the product and remove all the work that the vendor has put in, like their descriptions. This way, it actually saves just fine but lets them know it should be fixed without causing them frustration with YOUR platform.

As always, this is either added to your Child Theme’s functions.php file, or consider using the My Custom Functions Pro plugin to manage and organize all your snippets.

add_action( 'wcmp_before_post_update', 'wcmp_before_post_update_callback_imgs' );

function wcmp_before_post_update_callback_imgs(){

        //Main image both too short and too narrow (add >0 because error displayed when no image uploaded)
        if(isset( $_POST['featured_img'] )){
                $variable  = get_post_meta( $_POST['featured_img'],'_wp_attachment_metadata', false );
                if ( $variable[0]['width'] < 600 && $variable[0]['height'] < 600 && $variable[0]['width'] > 0 && $variable[0]['height'] > 0 ) {
                   wc_add_notice( "! Saved, but your main image is too small and will be blurry, please upload at least a 600px square image.", 'error' );
                }}

        //Main image too short
        if(isset( $_POST['featured_img'] )){
                $variable  = get_post_meta( $_POST['featured_img'],'_wp_attachment_metadata', false );
                if ( $variable[0]['width'] > 599 && $variable[0]['height'] < 600 ) {
                   wc_add_notice( "! Saved, but your main image is too short and will not display professionally, please upload at least a 600px square image.", 'error' );
                }}

        //Main image too narrow
        if(isset( $_POST['featured_img'] )){
                $variable  = get_post_meta( $_POST['featured_img'],'_wp_attachment_metadata', false );
                if ( $variable[0]['width'] < 600 && $variable[0]['height'] > 599 ) {
                   wc_add_notice( "! Saved, but your main image is too narrow and will not display professionally, please upload at least a 600px square image.", 'error' );
                }}                    
}

Tested and working on Woocommerce 4.6.1, WCMp 3.5.10

Is this no longer relevant or not working? Please let us know in the comments!

Comments on this post

Your email address will not be published. Required fields are marked *