Home Forums WC Vendors Pro Support Media Uploader Show Saved 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 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40560
    Daniel
    Participant

    Hello again…

    I’ve got our custom image uploader working fine… posting images from the product-edit.php based form to the product, and the front-end product page. Here’s the code:

    
    /* WC Vendors Pro - Add another file uploader to upload a file with the ID in a meta key */
    function wcv_upload_teacher_photo(){ 
    
    	$teacher_photo_ID = get_post_meta( get_the_ID(), 'wcv_custom_product_teacher_photo', true );
    	
    	WCVendors_Pro_Form_Helper::file_uploader( array(  
    		'header_text'		=> __('File uploader', 'wcvendors-pro' ), 
    		'add_text' 			=> __('Add file', 'wcvendors-pro' ),
    		'size'				=> 'thumbnail', 
    		'remove_text'		=> __('Remove file', 'wcvendors-pro' ), 
    		'image_meta_key' 	=> 'wcv_custom_product_teacher_photo', 
    		'save_button'		=> __('Add file', 'wcvendors-pro' ), 
    		'window_title'		=> __('Select an Image', 'wcvendors-pro' ), 
    		'value'				=> $teacher_photo_ID,
    		)
    	);
    }
    
    /* Show Teacher Photo in the WooCommerce Product Page */
    add_action('woocommerce_product_meta_start', 'wcv_show_teacher_photo', 2);
    
    function wcv_show_teacher_photo() {
    	$teacher_photo_ID = get_post_meta( get_the_ID(), 'wcv_custom_product_teacher_photo', true );
    	if (!is_null($teacher_photo_ID)) {
    		$teacher_photo = wp_get_attachment_image($teacher_photo_ID, 'thumbnail' , false );
    		echo $teacher_photo;
    	}; 
    } 
    

    The function ‘wcv_show_teacher_photo()’ is working beautifully on the product page. The function ‘wcv_upload_teacher_photo()’ is working, except for one issue; once the user saves the Product Edit form, the image doesn’t reload. The form acts as if there’s no image uploaded, though one has clearly been saved and is displaying correctly on the front end. How can I get the uploader to show the image that’s been saved on reload of the form? I’ve been at it for an hour, and have no idea why my code isn’t working. As far as I can tell, I’m loading the ‘value’ parameter correctly.

    Any help would be appreciated,

    Thanks!

    #40619
    Anna
    Member
    #40666
    Jamie
    Keymaster

    Hello,

    $teacher_photo_ID = get_post_meta( get_the_ID(), ‘wcv_custom_product_teacher_photo’, true );

    Is your problem. You can’t use get_the_ID() as you’re not in the wordpress loop.

    Change your function to add the object id as the argument in the function that you will pass.

    wcv_upload_teacher_photo( $object_id ){

    $teacher_photo_ID = get_post_meta( $object_id, ‘wcv_custom_product_teacher_photo’, true );
    .. }

    Then in your product-edit form call wcv_upload_teacher_photo( $object_id );

    That will pass the product id and retrieve the correct meta key for you.

    cheers,

    Jamie.

    #40760
    Daniel
    Participant

    Worked beautifully.

    Thanks!

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