How to include post image in notification [RESOLVED]

Hi,

I have a gravity form as an Enquiry form on each product page on my site. When the user submits the enquiry, both the user and the admin get an email. These are set up in the form’s Notifications section.

How can I include the photo of the product/post within the email notification?

There doesn’t seem to be a token I can use, similar to {embed_url} or {embed_post:post_title}

I was thinking I could set a value for a gravity form hidden field using javascript on the frontend so that it is submitted with the form, but that feels hacky and complicated. I’m sure there is a much more straight-forward way. Can anyone assist?

Thanks
Bas

Hello Bas. Is the image part of the post content, or is that stored in a custom field or as featured image for the post?

Hi Chris,

Its the product image for a Woocommerce product, which I think is equivalent of the post’s featured image.

Cheers
Bas

Hi Bas. I don’t have access to a Woocommerce site right now to test this out, but I believe you are correct. You can use one of the methods here to get the URL:

That code would be hooked to the Gravity Forms gform_field_value filter:

You could give a hidden text field in the form the dynamic population parameter name of ‘product_image’ or something like that, then use the code like this to populate the field with the URL of that product image:

add_filter( 'gform_field_value_product_image', 'populate_product_image' );
function populate_product_image( $value ) {
	// see https://stackoverflow.com/q/32837968
	$url = one of the methods from the above ^^^;
	return $url;
}

I don’t know the exact method to get that from Woocommerce, so I recommend looking at that Stack Overflow thread to find something current that works for you. Once you have the URL of the image, this code will populate the field with the URL to the image. Then, in your notification, you can use that URL like that, or wrap it in a url tag like this:

<img src='{Product Image Field:32}' />

(That would work if the URL is saved in field 32 in the form.)

Let me know if you need more assistance putting that together. Thank you.

1 Like

Getting the image URL in WP/PHP is not a problem. I just wasn’t sure how to get it from there into the Gravity Form. I’ll try out the hidden field & filter method and let you know how it goes. Thanks!

OK, let us know if you need some assistance once you give it a go.

That did the trick. Thanks Chris.

Thanks for the confirmation Bas.