make the product image required for a specific width and height

WCMp Core

make the product image required for a specific width and height Open

Viewing 5 reply threads
  • Author
    • #88133

      Hello guys,

      I want to make the product image required for the specific width and height 533px X 533px.
      Right now i am using this code

      add_action( 'wcmp_before_post_update', 'required_wcmp_product_field' );
      function required_wcmp_product_field(){
          $required_regular_price = isset( $_POST['_regular_price'] ) ? $_POST['_regular_price'] : '';
          $required_product_description = isset( $_POST['product_description'] ) ? $_POST['product_description'] : '';
          $required_feature_image = isset( $_POST['featured_img'] ) ? $_POST['featured_img'] : '';
          if(!$required_regular_price || !$required_product_description || !$required_feature_image ){
              wc_add_notice( __('برجاء التاكد من اضافة السعر و عنوان المنتج والوصف القصير والوصف الكامل للمنتج ', 'dc-woocommerce-multi-vendor'), 'error' );
              wp_redirect( apply_filters( 'wcmp_vendor_save_product_redirect_url', wcmp_get_vendor_dashboard_endpoint_url( get_wcmp_vendor_settings( 'wcmp_edit_product_endpoint', 'vendor', 'general', 'edit-product' ), $_POST['post_ID'] ) ) );

      which Feature image ,price and description are required . but i want to be sure all images that will added not less than 533px .. Can that happen ?

    • #88142
    • #88157

      Thanks @Moumita , But after i added this code to the function . Vendor not able to upload the profile image which is 100X 100 and can’t upload the shop cover which is 1200X390 . i also added the filter :


      at the function.php but filter didn’t work and vendors still can’t upload images for their profile or shop cover .

      that’s the code i used

      /** Upload image restriction ****/
      function resize_image_resolution($file) {
      		$image = getimagesize($file['tmp_name']);
      		    $minimum = array(
      		        'width' => '532',   //set your minimum
      		        'height' => '532'
      		    $maximum = array(
      		        'width' => '1201',  //set your maximum
      		        'height' => '1201'
      		    $image_width = $image[0];
      		    $image_height = $image[1];
      		    $too_small = "ابعاد الصورة صغير .. برجاء العلم ان الحد الادنى هو 533 *533";
      		    $too_large = "ابعاد الصورة اكبر من الحجم المسموح به . برجاء العلم ان الحد الاقصى للعرض والارتفاع 1200 بكسل";
      		    if ( $image_width < $minimum['width'] || $image_height < $minimum['height'] ) {
      		        $file['error'] = $too_small; 
      		        return $file;
      		    elseif ( $image_width > $maximum['width'] || $image_height > $maximum['height'] ) {
      		        $file['error'] = $too_large; 
      		        return $file;
      		        return $file;
      	} else {
      			return $file;
      add_filter('wp_handle_upload_prefilter', 'resize_image_resolution');
    • #88219

      @Bassem, if you check the above code you can see, the minimum and maximum file size have been restricted.
      So, if you upload a picture below this size/above the size, you will get the error.

      So, modify the size limit, as per your need.

    • #88232

      HI @Moumita , I meant if there a custom code just only for products not for all images.
      So i want only vendors can’t upload products images below the 533 px width and height . but of course i want them to be able to upload a profile pic and store cover.

    • #88272
Viewing 5 reply threads

Please LOGIN to reply to this topic

Buy any WCMp product at 20% discount, use code "FREEDOM20" or, buy bundle at a slashed price

Buy at Slashed Price