Skip Navigation

[Resolved] How to add different downloadable resources like PDF's and files to each product

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by tommyJ-3 2 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2307423
Product_field.PNG
Download_tab.PNG

In my product pages I have a tab called Nedladdning (Downloads). On this tab I want to show product specific datasheets, brochures and software files.

I have created a new product field (using Toolset) that shows up in all products pages (editing mode) but I am not sure which block I need to use in the product template in order to dynamically link this field to the product page. The File block just opens the media library and does not seem to have the dynamic content option.

So for example on the product tab for a thermal imager I want to add a PDF brochure, a datasheet, the latest software for analyzing thermal images and maybe the latest firmware for this product.

Can you assist?

#2307511

Hi,

Thank you for contacting us and I'd be happy to assist.

To show the formatted links with the file titles from the Toolset file type field having multiple instances, you can follow these steps:

1. You'll register a custom shortcode, that gets the titles and URLs of all the files saved in the file type custom field, and returns them in a list format:


add_shortcode( 'get-file-links', 'get_file_links_func');
function get_file_links_func($atts) {
	global $post;

	$types = "wpcf-{$atts['types_field']}";

	if ($types) {
		$urls = get_post_meta($post->ID,$types);
		$content = '<ul>';
		$testurl = '';

		foreach ($urls as $fileurl) {
			$arr = explode('/',$fileurl);
			$attachment_id = attachment_url_to_postid( $fileurl );
			$title = get_the_title($attachment_id);
			$content .= '<li><a href="'.$fileurl.'" title="'.$title.'" target="_blank">'.$title.'</a></li>';
			$test_url = $fileurl;
		}
		$content .= '</ul>';
	}

	if (!empty($test_url)) {
		return $content;
	} else {
		return 'No files available.';
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

2. Next, in your content template, you can include this new shortcode, to show the file links, like this:


[get-file-links types_field="field-slug"]

Note: You'll replace 'field-slug' with the actual slug of your file type field.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2307535

Hello
Thanks that worked!

I have a follow up question though.
In the image of the tabs I attached to this question, there is also a tab called "Tekniska data" (technical specifications).
I use the plugin Tablepress to create tables with technical specifications. That plugin is great as I easily can import technical specification tables in csv format from our old website. However... Each table is assigned a shortcode. How can I dynamically link the different tables and display them on the "Tekniska data" tab for each product? Something similar to the solution you gave me for the downloadable files?

EDITED: I worked it out myself. This is how I did it. Added a custom product field of the type WYSIWYG. In the product page I added the table's short code in this field. I then added a "paragraph" block under the tab Tekniska data in the template and linked it to the new field. Which worked! Should I use some other field types than WYSIWYG in the template and Paragraph in the template (maybe some other files are more efficient to use)?

#2307655

My issue is resolved now. Thank you!