• Resolved sjoerd89

    (@sjoerd89)


    Okay so at the moment i have renamed my additional information tab to downloads because in this tab is show files related to that product (such as pdf files). At the moment i have it set like this :

    <a href="http://www.example.com/media/{supplier[1]}/{product_pdf[1]}" target="_blank">Datasheet</a></strong>
    <a href="http://www.example.com/media/{supplier[1]}/{drawing_3d[1]}" target="_blank">Files</a></strong>

    This works fine for products that have those items in the database. But when the products do not have for example a product pdf the link will still be there and will link to a broken page since there is nothing there.

    Now what i want is, when i have a product pdf or specified download with that product it shows up and when there is nothing in the xml file there will be nothing to actually click on or show up.

    Now i hope this makes any sense to any of you and if not feel free to ask me more,

    have a great day.

    • This topic was modified 9 years, 3 months ago by sjoerd89.
    • This topic was modified 9 years, 3 months ago by sjoerd89.
    • This topic was modified 9 years, 3 months ago by sjoerd89.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @sjoerd89

    You can use an IF statement for this ( http://www.wpallimport.com/documentation/advanced/if-statements/ ). Example:

    [IF({product_pdf[1][.=""]})][ELSE]<a href="http://www.example.com/media/{supplier[1]}/{product_pdf[1]}" target="_blank">Datasheet</a></strong>[ENDIF]

    Hi I’m looking to do exactly that same thing. Are you able to describe the steps from assigning the file in WPAI Download & Import Attachments to having it display on the tab?
    Much appreciated.

    Thread Starter sjoerd89

    (@sjoerd89)

    What did you want to know?

    Hi Many thanks for the reply.
    I’ve created the extra Downloads tab in the functions.php & this displays fine, and I’ve added the WPAllImport ‘pmxi_attachment_uploaded’ functions edit, together with the csv element in the Download & Import Attachments section. What I’m missing is the information to take the attachment content and display in the tab. I’m assuming that the html is part of this, but don’t know where. The ‘icing’ would be your last question – how to only display the tab where there is a product attachment.
    Many thanks for the help

    Thread Starter sjoerd89

    (@sjoerd89)

    I went about it in a completely other way so if you are already using the standard “additonal information” tab this will not be for you i gues. I am sure what you did is possible but not sure how.

    What i did is use the 2 standard woocommerce tabs, the first one is description i think and the second one is additional information. I changed the names of these tabs in what i liked (in my case product info & downloads and accessoiries)

    The first tab is used for the attributes from the products and the second is used to display my downloads for that product. Both of these tabs are accessible by using the wp-all import woocommerce add on.
    http://www.zilvertron.com/product/8985a102-dc-borstel/ <- a page to show u what i mean.
    Now for the info displayed in this tab i used the if statements to display information when the product has this:

    [IF({product_pdf[1][.=””]})][ELSE]Datasheet[ENDIF]

    Now this will always show the tab i don’t know if it is possible to only show the tab when there is information in there.

    Now if i want to make a extra tab to add information they send me this:
    https://ww.wp.xz.cn/plugins/custom-product-tabs-wp-all-import-add-on/
    I have not used that yet since i didnt update the woocommerce plugin to the 3.0 + versions since it still has some bugs that need to be fixed first. I hope you understand any of this and if this was of any help.

    • This reply was modified 9 years, 1 month ago by sjoerd89.

    That’s exactly what I want to do πŸ™‚
    How do I take the uploaded attachment from WPAI & display the information on a tab? (Sorry if this is a bit simple)
    Ta

    Thread Starter sjoerd89

    (@sjoerd89)

    If you have the attachment file on your server just use something like this
    [IF({product_pdf[1][.=""]})][ELSE]<a href="http://www.example.com/media/{supplier[1]}/{product_pdf[1]}" target="_blank">Datasheet</a>

    In this case it says if the product pdf – a cell in my excel file is empty show nothing when theres information show the link. In my case it is a datasheet. You can change the [1] items to the fields you use yourself.

    • This reply was modified 9 years, 1 month ago by sjoerd89.
    • This reply was modified 9 years, 1 month ago by sjoerd89.
    • This reply was modified 9 years, 1 month ago by sjoerd89.
    stevebower

    (@stevebower)

    I’ve been trying to do this, and after piecing a few functions together, here is the complete snippet from my functions.php. I’ve commented the sections. Feel free to make any tweaks if you think it could be improved. Don’t forget to add the attachment path in Other Product Options>Download & Import Attachments:

    // Upload the Data Sheet & add the url to a Custom Field (data_sheet)

    function my_attachment_uploaded($post_id, $att_id, $file) {
    $attachment_url = wp_get_attachment_url($att_id);
    update_post_meta($post_id, “data_sheet”, $attachment_url);
    }

    add_action(‘pmxi_attachment_uploaded’, ‘my_attachment_uploaded’, 10, 3);

    // Add a new tab for Data Sheets:

    add_filter( ‘woocommerce_product_tabs’, ‘data_sheet_tab’ );
    function data_sheet_tab( $tabs ) {
    // Add the new tab
    $tabs[‘data_sheet_tab’] = array(
    ‘title’ => __( ‘Data Sheet’, ‘text-domain’ ),
    ‘priority’ => 30,
    ‘callback’ => ‘data_sheet_tab_content’
    );
    return $tabs;
    }

    // The new data_sheet_tab_content
    function data_sheet_tab_content() {

    echo ‘<h2>Data Sheet</h2>’;

    // Left this in for info as its the clever bit that gets the datasheet url from the data_sheet custom field:
    // echo get_post_meta( get_the_ID(), ‘data_sheet’, true );
    //

    // Puts the url on the tab, or, if empty, a message

    if( get_post_meta( get_the_ID(), ‘data_sheet’, true ) )
    { echo ‘Datasheet‘;
    }
    else
    {
    echo ‘No data sheet available’;
    }

    }
    // ends

    Thread Starter sjoerd89

    (@sjoerd89)

    Looks good i will try this out myself on a test site πŸ™‚

    stevebower

    (@stevebower)

    Hmm my url script was ‘run’ rather than showing the code. Trying this

    
    // Upload the Data Sheet & add the url to a Custom Field (data_sheet)
    
    		function data_sheet_upload($post_id, $att_id, $file) {
    			$attachment_url = wp_get_attachment_url($att_id);
    			update_post_meta($post_id, "data_sheet", $attachment_url);
    		}
    
    		add_action('pmxi_attachment_uploaded', 'data_sheet_upload', 10, 3);
    
    	// Add a new tab for Data Sheets:
    
    		add_filter( 'woocommerce_product_tabs', 'data_sheet_tab' );
    		function data_sheet_tab( $tabs ) {
    			// Add the new tab
    			$tabs['data_sheet_tab'] = array(
    				'title'       => __( 'Data Sheet', 'text-domain' ),
    				'priority'    => 30,
    				'callback'    => 'data_sheet_tab_content'
    			);
    			return $tabs;
    		}
    		 
    	// The new data_sheet_tab_content
    		function data_sheet_tab_content() {
    		
    		echo '<h2>Data Sheet</h2>';
    		
    	//  Left this in for info as its the clever bit that gets the datasheet url from the data_sheet custom field:
    	//	echo get_post_meta( get_the_ID(), 'data_sheet', true );
    	//
    		
    	// Puts the url on the tab, or, if empty, a message
    		
    		if( get_post_meta( get_the_ID(), 'data_sheet', true ) )
    
    		{ echo '<strong><a href="' . get_post_meta( get_the_ID(), 'data_sheet', true ) . '" target="_blank"><img style="float: left; margin-right:15px;" src="https://demo.intersafety.co.uk/wp-content/uploads/pdf.png" height="35px" width="35px">Datasheet</a></strong>';
    		}
    		else
    		{
    			echo 'No data sheet available';
    		}
    
    		}
    // ends
    
    Thread Starter sjoerd89

    (@sjoerd89)

    Do you use the custom fields add-on for this?

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Show extra files’ is closed to new replies.