Home Forums WC Vendors Free Support Force Required Image

NOTICE: We've Moved to a Ticket System for Support

As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system.  This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.

For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.

If you are a WC Vendors Pro customer please open a support ticket here. 

If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.

The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 17 posts - 1 through 17 (of 17 total)
  • Author
    Posts
  • #36660
    BradGriffin
    Participant

    I’m about to go code digging, but before the weekend begins…. quick question.

    I need to make it mandatory that the vendor submits a featured image.

    searched: force image, featured image, require image, ……….

    #36773
    WC Vendors Support
    Participant
    #38566
    dave
    Participant

    Hi,

    I am having the same problem, but i can’t seem to find the one for required the featured image in that list

    #38567
    dave
    Participant

    and would also like to force width/height/length and weight to be required also

    #38570
    dave
    Participant

    I’m on WC Vendors pro, though I don’t think that makes a difference and I didnt want to start a new thread

    #38588
    Anna
    Member

    For the product featured images, I think you may need to work with has_post_thumbnail and the_post_thumbnail rather than the Wc vendors filters..
    I will have someone else confirm this, though, @DavidH

    #38590
    Jamie
    Keymaster

    Hello,

    This plugin should do it (note: i didn’t try it just read the source code and description).

    cheers,

    Jamie.

    #38609
    dave
    Participant

    ah okay, so it’s just through wordpress as normal,

    i’ll do that,

    cheers

    #39643
    Daniel
    Participant

    Hello,

    I’m trying to do the force featured image thing too, requiring a featured image for vendor-submitted products before submission is allowed. I tried the plugin mentioned above to no avail. So I’m thinking it will have to happen through code. Ran into the same problems as the people above, as the product media uploader is coded differently than the other product fields. Any further details on how to work with has_post_thumbnail and the_post_thumbnail would be greatly appreciated.

    Thanks!

    #39661
    Anna
    Member

    There are a few options here you can try…
    http://stackoverflow.com/questions/12410402/require-authors-to-set-featured-image-for-post

    Or something like this: (I do NOT know if this works, so just try it and work with it…!)

    function require_featured_image() {
         if(!has_post_thumbnail()) {
              wp_die( 'Your product does not have a featured image. Please go back and include a featured image' ); 
         } 
    }
    add_action( 'pre_post_update', 'require_featured_image' );
    
    #39772
    Mubasher
    Participant

    @digitalchild Thankyou for the plugin link it worked like a charm. Activated and selected settings of the plugin and checked the product box. The only thing I think it can improve with is on returning the user back to the same page or only a pop up warning box.

    #39795
    Jamie
    Keymaster

    Hello @shah,

    It’s not our plugin so I would recommend contacting the plugin author and giving some suggestions 🙂

    cheers,

    Jamie.

    #42862
    Daniel
    Participant

    @fervous, the code snippet you posted works quite well. If there’s a way to have it throw an error on the form as the other fields do, rather than use ‘wp_die’ that would make for a much better user experience. I think being able to handle that aspect is worth at least a little digging. I may dig around to figure out how to do that for a bit, but any suggestions here would be welcome.

    Also worth noting, the plugin that’s been suggested threw an error regardless of whether I had a featured image or not, and regardless if it was sized appropriately. I know it’s not a WC Vendors plugin, but thought it would be worth mentioning here for other people who might be trying to accomplish similar goals.

    Thanks!

    #42870
    Daniel
    Participant

    Okay, so spending a couple of hours tinkering with how to require a featured image, and have the error come up on the Edit Product page rather than in the WP_Die screen and confues users, the idea came to me that I could create an additional, required wcv custom field that would be hidden with CSS. The value of that field – and its associated meta-key – would get updated automatically depending on whether the product has a featured image attached, in other words if has_post_thumbnail() returns TRUE or FALSE. Since a FALSE result would update the value of the associated field, and the field is required, voila, a data-error message gets thrown.

    I have it working… almost. I’ll mention what I need help with below.

    Here’s the code in the product-edit form:

    
    	<div class="all-100"> 
        	<!-- Media uploader -->
    		<div class="wcv-product-media">
    			<?php WCVendors_Pro_Form_helper::product_media_uploader( $object_id );
    			
    			// Hidden field - Pass the has_thumbnail() value to its metatag value & throw an error on the page if there's no custom field
    			
    			// do_action( 'check_for_featured' , $object_id );
    			
    			// Create the hidden field and the associated meta-key.
    			
    			$has_thumb = get_post_meta( $object_id , 'wcv_custom_product_has_thumbnail', true );
    			$has_thumb == 1 ? $f = '1' : $f = '' ;
    			
    			WCVendors_Pro_Form_Helper::input( array(  
    				 'type'      => 'text',
    				 'post_id'   => $object_id, 
    				 'id'     => 'wcv_custom_product_has_thumbnail',  
    				 'label' => __('Has Featured Image', 'wcvendors-pro'),
    				 'placeholder'   => __( 'Has Featured Image', 'wcvendors-pro' ), 
    				 'wrapper_start' 	=> '<div class="hidden-field">',
    				 'wrapper_end' 		=> '</div>',		
    				 'value' => $f,
    				 'custom_attributes' => array(
    				 	'data-rules' => 'required',
    					'data-error' =>  __( 'Please add a Featured Image.', 'wcvendors-pro') )
    			) );
    			
    			do_action( 'check_for_featured' , $object_id );			
    						
    	?>
       </div>
    
    

    The Media Uploader in the code content above is the one that comes standard with the product-edit.php template, so the code I’ve added is below.

    Here’s what I’ve got in the associated plugin file (it could run via the functions.php file just as well):

    
    // REQUIRE THE FEATURED IMAGE
    function check_product_featured_image( $product_id ) {
    	
    	global $product;
    	global $post;
         
    	$post_type = get_post_type( $product_id );
    	$post_thumb = has_post_thumbnail( $product_id );
    		 
    	if ( $post_thumb && $post_type == 'product' ) {  
    		 	$has_featured = "1"; 
    		}	
    	else { 
    		$has_featured = "0"; 
    		}
    
    	update_post_meta( $product_id , 'wcv_custom_product_has_thumbnail' , $has_featured );
    
    }
    
    add_action( 'check_for_featured' , 'check_product_featured_image' );
    add_action( 'pre_post_update' , 'check_product_featured_image' );
    add_action( 'wcv_save_product_meta', 'check_product_featured_image', 10 );
    

    The field updates successfully, except in the one condition that matters once – when there’s no existing featured image on form load, then the user uploads one. Since the field doesn’t update until the form is saved, the unchanged meta data in my custom field doesn’t change, and still throws the error (I think this may have been the issue with the plugin suggested in this thread as well).

    So… How can I get the metadata and field to update when the image is added or removed? It would be great if there’s a place to hook into, or a function to call, and I figure there must be, because the “Add/Remove” text changes depending on there being an image, updating in real time.

    Thanks for your help!

    #43211
    Daniel
    Participant

    Resubmitted the last post on a new thread:

    Thanks

    #51108
    Joseph Anthony
    Participant

    this isn’t working

    #51128
    Anna
    Member

    We didn’t write that.
    In the next Pro release there will be an option in admin settings to force featured image.

Viewing 17 posts - 1 through 17 (of 17 total)
  • The forum ‘WC Vendors Free Support’ is closed to new topics and replies.