Image Field – Wc Fields Factory

Product Field

Image field type not available for Product Page (instead File field could be used).

Admin Field

Insert a Image uploader field on the Admin Page. Using this field strore admin can set custom images to Products, Variation Products and Product Category.
This field utilize WordPress Media Browser to browse or upload images.

Option Description
Button Text Uploader button label’s text.
Probe Text Description for this image uploader.
Media Browser Title Descriptive title for the WordPress Media Browser.
Required Make this image field mandatory – user cannot perform create or update operation on without choosing any image.
Message Message that has to be displayed when validation failed for this field.
How to use this field

This field will store the image’s attachment id as the value. like every other custom admin fields, this also will be stored as Custom Post Meta. Where the meta key would be the name of the field itself with “wccaf_” as prefix.
If you wanted to use this field’s value (I mean you wanted to retrieve the image) here is the snippet.

 * $_post_id would be the Product Id
 * Note: Post meta key is the field's name itself with "wccaf_" as prefix
$attachment_id = get_post_meta($_post_id, "wccaf_your_image_field_name", true);

/* Use the following if you want the image with img tag wrapped */
$img_html = wp_get_attachment_image($attachment_id, 'full');

/* Use the following if you want only the attachment URL */
$img = wp_get_attachment_image_src($attachment_id, 'full');

/* $img[0] contains the SRC */
$html = '<img src="'. $img[0] .'" />';

Leave a Reply

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


2 Comment(s)

  1. Berdych December 23, 2017

    This does not work for me if I want to upload multiple images to a product. Admin settings: Product settings: -> The third button has the same title in the modal window: ‘Choose an image #1’ and WP media script uploads all images to the first field…

    1. Saravana Kumar K December 28, 2017

      Thanks for reporting this, I missed to test this scenario, will update soon.