> ## Documentation Index
> Fetch the complete documentation index at: https://pitchprint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to attach customer designs to email (Word Press)

> Add each customer's PitchPrint PDF as an attachment on WooCommerce order emails by pasting a snippet into your email template.

The following is an article on having your customer's designs attached to an email.

<Note>
  **Note: This code has been written only for Woocommerce Cart plugin with WordPress.**
</Note>

Kindly follow these instructions:

<Steps>
  <Step title="Copy the email template to your theme">
    Move your email template to your theme folder so you may edit it.

    1. Backend -> Woocommerce -> Settings -> Emails -> Select Template -> Copy file to theme.
    2. Remember theme template location to use in the following step.
  </Step>

  <Step title="Paste the attachment code">
    Place the below code **at the bottom** of your desired email template file (location of file remembered in above step).

    ```php theme={null}
        /* PitchPrint Attachments Start*/

        /*
         * Delete files greater than 5 minutes old
         */
        function custom_delete_old_pp_designs($dir)
        {
        	$lifeTime = time() - 300;

        	foreach (glob("$dir/*.pdf") as $file) {
            	if (filemtime($file)  < $lifeTime) unlink($file);
        	}
        }

        /*
         * Saves PitchPrint items design to your server
         */
        function custom_get_pp_pdf($ppPdfBase, $pId, $dest)
        {
        	$file 		= $dest."/MyDesign_".time().'.pdf';
        	$getFile 	= "$ppPdfBase=$pId";

        	$success 	= copy($getFile, $file);

        	if ($success) return $file;
        	return false;
        }

        /*
         * Returns PP Attachments for email
         * And empties folder from old pp designs
         */
        function custom_append_pp_designs($obj)
        {
        	$ppFetchPDFBaseUrl  = 'http://pdf.pitchprint.io?id';
        	$pluginUpldDir 		= get_home_path().'wp-content/plugins/pitchprint/uploader/files';
        	$data 				= [];

        	// Remove old designs from upload dir
        	custom_delete_old_pp_designs($pluginUpldDir);

        	// Fetch all PitchPrint designs in this order
        	foreach ($obj->get_items() as $item_id => $item) {

        		$meta = wc_get_order_item_meta($item_id, '_w2p_set_option');

        		if ($meta) {
                    $ppData =  (strpos($meta,'%7') !== FALSE) ? json_decode(urldecode($meta)) : json_decode($meta);

                    if ( isset($ppData->files) ) {

                     	foreach ($ppData->files as $file) {

                            $regex = "/http.*?uploader\/files/";

        				    $result = preg_replace($regex, $pluginUpldDir, $file);

                            $data[] = $result;

                        }

                    } else {
        				$pId 	= $ppData->projectId;
        				$data[] = custom_get_pp_pdf($ppFetchPDFBaseUrl, $pId, $pluginUpldDir);
                    }
        		}

        	}

        	// Return attachments
        	return $data;
        }

        function attach_pitchprint_designs_pdf_to_email ( $attachments , $id, $object, $new ) {
        	return custom_append_pp_designs($object);
        }

        add_action( 'check_pitchprint_item_need_attach', 'custom_attach_pitchprint_designs');

        /*
         * Check whether we need to append the attachments.
         */
        function custom_attach_pitchprint_designs($obj)
        {
        	foreach ($obj->get_items() as $item_id => $item) {

        		$meta = wc_get_order_item_meta($item_id, '_w2p_set_option');

        		if ($meta) {

        			add_filter( 'woocommerce_email_attachments', 'attach_pitchprint_designs_pdf_to_email',10, 4);

        			return true;
        		}
        	}
        }

        do_action('check_pitchprint_item_need_attach', $order);

        /* PitchPrint Attachments End*/
    ```
  </Step>

  <Step title="Set the upload folder permissions">
    Ensure wp-content/plugins/pitchprint/uploader/files 777 permissions.
  </Step>

  <Step title="Send yourself a test order email">
    Run a test by emailing yourself on an order, with a PitchPrint design item and the selected status you chose for your template/s.
  </Step>
</Steps>

## Related articles

<CardGroup cols={2}>
  <Card title="How to show customer design previews on email (WordPress)" icon="image" href="/docs/tutorial/how-to-show-customer-design-previews-on-email-wordpress">
    Display customer design previews inside WooCommerce order emails.
  </Card>

  <Card title="Add previews & project file links to Shopify email notifications" icon="envelope" href="/docs/tutorial/add-previews-project-file-links-to-shopify-email-notifications">
    Add PitchPrint previews and PDF links to Shopify order emails.
  </Card>

  <Card title="How to email artwork to customers" icon="envelope" href="/docs/tutorial/how-to-email-artwork-to-customers">
    Options for emailing finished customer artwork.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.