How to add HTML elements into email templates in WooCommerce? - email

I've seen many articles about WooCommerce email customization, but I can't find any that explains how to actually modify the page structure of the emails. For my project I need to add new page elements containing text and images. I want to actually build my emails as I would build a page.
Echoing stuff in email templates doesn't seem to work though. If I take templates/emails/customer-completed-order.php, echo things in it then preview the result using Email Log plugin, it doesn't make any difference: my echos don't render.
Are WooCommerce emails actually impossible to customize in depth?

Go to this folder:
plugin/WooCommerce/template/emails
copy the folder emails to your theme folder then modify php files in emailsfolder
If your change not actually work check this article:
https://docs.woothemes.com/document/template-structure/
also some plugin available for create custom Email template

Woocommerce emails can be customized but only to certain extent.
Content of any single email are strucuted in a little complicated manner.
E.g. The header part of the email is rendered from file email-header.php. Footer part of the email is rendered from file email-footer.php. Again for each different type of there are different template files, such as customer-invoice.php, customer-new-account.php, customer-processing-order.php etc. Contents of the emails are also called from different hooks and functions. Again all the email elements are embeded with inline styles. These styles are defined in yeat another file email-styles.php. Strange you can't easily find reference of this file in any of the email templates.
Regarding adding additional content/information in the emails should be possible.

In theme functions.php, please create a two hook to add new content or apply HTML tags:
function add_order_email_instructions( $order, $sent_to_admin )
{
$order_id = $order->get_id();
if(!$sent_to_admin)
{
//Your message or code
}
else
{
//Your message or code
}
}
add_action( 'woocommerce_email_before_order_table', 'add_order_email_instructions', 10, 2 );
add_filter( 'woocommerce_email_headers', 'new_order_reply_to_admin_header', 20, 3 );
function new_order_reply_to_admin_header( $header, $email_id, $order )
{
if ( $email_id === 'new_order' ){
$email = new WC_Email($email_id);
$header = 'MIME-Version: 1.0' . "\r\n";
$header = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
}
return $header;
}

Related

RealURL used in email link

In the Typo3 backend I'm redering my email body with a Fluid template. In the following way:
$emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$templateName = 'path/to/email/template.html';
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$templateRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']);
$templatePathAndFilename = $templateRootPath . $templateName;
$emailView->setTemplatePathAndFilename($templatePathAndFilename);
$emailView->assignMultiple($variables);
$emailBody = $emailView->render();
In the loaded email template I'm making an absolute link to a page with the following line:
<f:link.action absolute="true" pluginName="name" extensionName="extName" pageUid="{PageId}" controller="Ads" arguments="{uid: uid}">Klik hier</f:link.action>
This is generating a working link only it is not processed by RealURL. Is it possible that is will be done?
You need a valid frontend context for realurl to work. Therefore I suggest that you move your email template to a page type and use a subrequest to render the HTML.

SugarCRM - Custom Print Layout

I created a model in SugarCRM and I need to print the details view. But this must be printed with a different layout.
It must have the company logo for example, if I just wanted do print the bean information, the default print would be sufficient, but I need something closer to a report, because this info will be given to the costumer.
I would like to know if there is a way to create a printing template, and if there is, how can I create one?
Thanks for your help, if you need more information please comment.
rfnpinto
Even in SugarCRM CE you can leverage the included Sugarpdf class, which is an extension of TCPDF.
If you have SugarCRM Professional you can find examples of this in the Quotes module. If not, you're flying blind, so I can give you the gist of it.
Using the Contacts module as an example, create /custom/modules/Contacts/views/view.sugarpdf.php with contents like the following:
<?php
require_once('include/MVC/View/views/view.sugarpdf.php');
/**
* this defines the view that will drive which PDF Template we use
*/
class CustomContactsViewSugarpdf extends ViewSugarpdf{
public function display(){
$this->sugarpdfBean->process();
$this->sugarpdfBean->Output($this->sugarpdfBean->fileName,'D');
sugar_die('');
}
}
Create /custom/modules/Contacts/sugarpdf/sugarpdf.pdfout.php with contents like the following:
$contact = BeanFactory::getBean($_REQUEST['record_id']);
if(empty($contact->id)){
sugar_die('Could not load contact record');
}
$name_str = "<p><strong>Name: {$contact->name}</strong></p>";
$this->writeHTML($name_str);
$this->drawLine();
}
function buildFileName(){
$this->fileName = 'ContactPDFOut.pdf';
}
}
From there, you can print a PDF document per your format if you hit the URI index.php?module=Contacts&action=sugarpdf&sugarpdf=pdfout&record_id=1234
Once that's working in the way you want, you can add a button the Contacts Detailview to access that URI more easily. Dig into /custom/modules/Contacts/metadata/detailviewdefs.php and find the existing buttons array. It'll look something like this:
'buttons'=>array('EDIT', 'DUPLICATE', 'DELETE', 'FIND_DUPLICATES'
Just enhance this with your own button and hidden input
'buttons'=>array('EDIT', 'DUPLICATE', 'DELETE', 'FIND_DUPLICATES',array(
'sugar_html'=>array(
'type' => 'submit',
'value' => '(Wrongfully Hardcoded Label) Print PDf',
'htmlOptions'=>array(onclick => 'this.form.action.value=\'sugarpdf\';this.form.sugarpdf.value=\'pdfout\'')
)
)
...
The hidden array should be part of $viewdefs['Meetings']['DetailView']['templateMeta']['form'] and defined like so:
'hidden' => array('<input type="hidden" name="sugarpdf">'),
I haven't tested this recently but this is the general idea of adding custom Print PDF abilities to any particular screen within SugarCRM. TCPDF options are pretty extensive and forming the template just right is going to be very tedious, but I think once the "plumbing" is working here you'll figure that bit out, but feel free to ask followup questions.

Create a downloadable table from a form submit

Ok, so my last question was closed because I didn't quite ask it the proper way... What I want to do is, create an HTML form that when submitted outputs the form in a table format and allows you to download that file, or does it automatically, so I guess in short... user navigates to page, fills out form, hits submit, and HTML table asks to download. I hope I asked this correctly . This is something that would help agents at my call center organize and save their abundance of login names and passwords, Thanks
i did a quick google.
you will want to get the form to submit the data (with possible client side validation)
then do any server side data validation if needbe.
then output the data as a table.
you can also export the table with php code like explained here if you will be opening it with excel for instance.
Have you tried existing services, such as Google Forms?
To expand on jskye, it would be something like this to create an HTML table.
//Get POST data from Form
$formData_Name= $_POST['Name'];
$formData_Age= $_POST['Age'];
$formData_Message= $_POST['Message'];
//Modify header information so it knows to download this and how to save it
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=table.htm");
//Print headers to table
print "<html><body><table>\n\t".
"<tr>\n\t\t".
"<th>Name</th>\n\t\t".
"<th>Age</th>\n\t\t".
"<th>Message</th>\n\t".
"</tr>";
//Print form data to table
print "<table>\n\t".
"<tr>\n\t\t".
"<td>". $formData_Name ."</td>\n\t\t".
"<td>". $formData_Age ."</td>\n\t\t".
"<td>". $formData_Message ."</td>\n\t".
"</tr>";
//Close form data
print .= "</table></body></html>";

in drupal 7, adding a form to a view produces multiple same forms because of multiple attachment , how to keep only one?form

I am adding a comment form to a view, in fact, in this view I have 3 attachments, so when I finally added one form in the view.tpl.php through the code
$comment = new stdClass;
$comment->nid = arg(2);
$form = drupal_get_form('comment_node_project_form', $comment);
print render($form);
I can see there are 4 forms on the page, although I only need one form in that view, how to remove the additional ones ?
Use your code only in needed view.tpl.php. Templeates listed in "Theme information" of a view configuretion. You print your form in temeplate named yout_view_id_view.tpl.php or similar. I recomend you to read documentation on drupal.org.

Loading view file into a variable in Zend Framework

I am trying to send mail using mail templates. To do this I want to load a .tpl into a variable. Instead of loading an HTML file and substituting placeholders, I wonder if it is possible to set values of the view in the controller, and then load this view into a variable. This way I would have a variable containing the HTML mail filled out with the information set in the controller prior to loading the view.
Any alternatives are also welcome, I mean, if there are already ways of doing mail templating in a more standardized way.
A great idea Erik, and I've done this many times.
Zend_View is really just a templating system, and can be used to generate anything, not just HTML.
Sample code - create a view, assign some data, render the view and send the mail!
$view = $this->getHelper('ViewRenderer')->view;
$view->email = $data['email'];
$view->password = $data['password'];
$text = $view->render('mail/new-user.php');
$mail = new Zend_Mail();
$mail->addTo($data['email'], $data['forename'] . ' ' . $data['lastname']);
$mail->setSubject('Account Details');
$mail->setBodyText($text, 'utf-8');
$mail->send();
In the first line I retrieve the ViewRenderer's view so I have access to the normal script paths. You can create a new Zend_View object, but you'll need to add the path to your view scripts manually.
In my example text based content is generated, but you could generate HTML all the same.
Sorry guys (and girls). My google skills must have noticed it was early in the morning. I found what I was looking for here:
http://myzendframeworkexperience.blogspot.com/2008/09/sending-mails-with-templates.html