Zen Cart Logo
Forums / General Questions / Adding extra fields to admin copy of order confirmation email, and orders area.

Adding extra fields to admin copy of order confirmation email, and orders area.

Views: 4,468

Results 21 to 30 of 30
17 Mar 2013, 10:19 AM
#21
david_allen avatar

david_allen

Zen Follower

Join Date:
Feb 2008
Location:
Amersham, Buckinghamshire, United Kingdom
Posts:
141
Plugin Contributions:
1

Adding extra fields to admin copy of order confirmation email, and orders area.

sports guy:

This was in my error log:

I did change to your suggestion above and the same thing. Since the above error says this: 'extrafield1' is unknown in the field list and I see this code: "$account->fields['customers_extrafield'], 'id="extrafield"')" in another area of the module, should I try and change extrafield1 to customers_extrafield?

Maybe something like this:

echo $extra_field->fields['customer_extrafield'];

Also shouldn't this: Select extrafield1, extrafield2, extrafield3 be: Select customer_extrafield, customer_extrafield2, customer_extrafield3? I am seeing customers_extrafield, customers_extrafield2, customers_extrafield3 in the database under customers!

Yes - it looks like those are the fieldnames to use.

The

$extra_field->fields['customer_extrafield'] is then used as in your original post

$email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" . 
$this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .     
$extra_field->fields['customer_extrafield1']. "\n\n" .     
$extra_field->fields['customer_extrafield3']. "\n\n" .     
EMAIL_THANKS_FOR_SHOPPING . "\n" . 
EMAIL_DETAILS_FOLLOW . "\n"  ...etc

where they are being added to $email_order

Regards

23 Mar 2013, 2:46 PM
#22
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Ajeh and David,

I was finally able to get this thing to work with your help. There is one more small issue that maybe you can help me with (It is listed in bold toward the bottom of the post). The issue was the extra listing field definitions. The debug logs, kept telling me my extra field definitions were wrong. This is the correct coding that works:

Around line #940 or order.php

    //extra fields addition
    global $db;
    $extra_query ="SELECT customers_extrafield, customers_extrafield2, customers_extrafield3 from ".TABLE_CUSTOMERS." WHERE customers_id = '".$_SESSION['customer_id'] ."'";
    $extra_field = $db->Execute($extra_query);
    echo 'I SEE: ' . $extra_field->fields['customers_id'];

And then around line #946 (Additions are in red):

    //intro area
    $email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
    $this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
    $extra_field->fields['customers_extrafield']. "\n\n" .
    $extra_field->fields['customers_extrafield2']. "\n\n" .   
    $extra_field->fields['customers_extrafield3']. "\n\n" .
    EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
    EMAIL_SEPARATOR . "\n" .

For anyone following this post, there is no customers_extrafield1, it gets skipped.

Hopefully there are a few things you can help me with. I have the answers to each question, so how would I add the question? Another words my order e-mails look like this:

Residence
OH
Columbus, OH

Instead of:
Is this being shipped to a business or residence? Residence
Chapter Letters: OH
Chapter City and State: Columbus, OH

Could I make an easy addition to these lines?

$extra_field->fields['customers_extrafield']. "\n\n" .
    $extra_field->fields['customers_extrafield2']. "\n\n" .   
    $extra_field->fields['customers_extrafield3']. "\n\n" .

And second these lines are each double spaced instead of single spaced on the e-mail. Another words they look like this:
Residence

OH

Columbus, OH

Instead of this:
Residence
OH
Columbus, OH

I assume I have the combine the 3 definitions to one line and add a <br />, but I am not sure how to do this. Would it be an easy fix to get these lines single spaced?

23 Mar 2013, 6:52 PM
#23
david_allen avatar

david_allen

Zen Follower

Join Date:
Feb 2008
Location:
Amersham, Buckinghamshire, United Kingdom
Posts:
141
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

sports guy:

Ajeh and David,

//intro area
$email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
$this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
$extra_field->fields['customers_extrafield']. "\n\n" .
$extra_field->fields['customers_extrafield2']. "\n\n" .   
$extra_field->fields['customers_extrafield3']. "\n\n" .
EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
EMAIL_SEPARATOR . "\n" .
> 
> For anyone following this post, there is no customers_extrafield1, it gets skipped.
> 
> **Hopefully there are a few things you can help me with.** I have the answers to each question, so how would I add the question? Another words my order e-mails look like this:
> 
> Residence
> OH
> Columbus, OH
> 
> Instead of:
> Is this being shipped to a business or residence? Residence
> Chapter Letters: OH
> Chapter City and State: Columbus, OH
> 
> **Could I make an easy addition to these lines?**
> ```
$extra_field->fields['customers_extrafield']. "\n\n" .
    $extra_field->fields['customers_extrafield2']. "\n\n" .   
    $extra_field->fields['customers_extrafield3']. "\n\n" .

And second these lines are each double spaced instead of single spaced on the e-mail. Another words they look like this:
Residence

OH

Columbus, OH

Instead of this:
Residence
OH
Columbus, OH

I assume I have the combine the 3 definitions to one line and add a <br />, but I am not sure how to do this. Would it be an easy fix to get these lines single spaced?

Try something like this

    //intro area
    $email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
    $this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
    'Is this being shipped to a business or residence? '.$extra_field->fields['customers_extrafield']. "\n" .
    'Chapter Letters: '.$extra_field->fields['customers_extrafield2']. "\n" .   
    'Chapter City and State: '.$extra_field->fields['customers_extrafield3']. "\n" .
    EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
    EMAIL_SEPARATOR . "\n" .

note the removal of a '\n' at the end of each of your extra lines - that should get rid of the double spacing.

Regards

23 Mar 2013, 10:35 PM
#24
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Go to phpMyAdmin and look at the table:
customers

are the fields called:

customers_extrafield1
customers_extrafield2
customers_extrafield3

or are they called:

customers_extrafield
customers_extrafield2
customers_extrafield3

or are they called something else?

23 Mar 2013, 11:20 PM
#25
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Ajeh:

or are they called:

In phpMyAdmin they are called your second option which is:

customers_extrafield
customers_extrafield2
customers_extrafield3                      
23 Mar 2013, 11:48 PM
#26
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

David Allen:

Try something like this

//intro area
$email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
$this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
'Is this being shipped to a business or residence? '.$extra_field->fields['customers_extrafield']. "\n" .
'Chapter Letters: '.$extra_field->fields['customers_extrafield2']. "\n" .   
'Chapter City and State: '.$extra_field->fields['customers_extrafield3']. "\n" .
EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
EMAIL_SEPARATOR . "\n" .
> 
> note the removal of a '\n' at the end of each of your extra lines - that should get rid of the double spacing.
> 
> Regards

David, I am almost there. First adding the text as you suggested did add the question to the e-mail just like I was asking. So that is great! My only issue now is a small e-mail format issue. Instead of a single space, it puts all three items on one line (inline) instead of single spacing like a <br /> tag.

This Code:

. "\n\n" .

Looks like this:

Chapter Letters: OH

Chapter City and State: Columbus, OH

Is this being shipped to a business or residence? Residence Chapter Letters: OH Chapter City and State: Columbus, OH

 
And This Code:

. "\n" .

Looks like this:

Is this being shipped to a business or residence? Residence Chapter Letters: OH Chapter City and State: Columbus, OH


I am looking for this:

Is this being shipped to a business or residence? Residence
Chapter Letters: OH
Chapter City and State: Columbus, OH

23 Mar 2013, 11:55 PM
#27
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Hmmmm. ```
. "\r\n" .

26 Jul 2013, 3:07 PM
#28
sports_guy avatar

sports_guy

Totally Zenned

Join Date:
Apr 2007
Location:
Dayton, Ohio
Posts:
682
Plugin Contributions:
0

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

Final Coding:

For those following, I was only able to get my extra fields to be sent in the order confirmation e-mail. I was not able to get them posted in the order area. If you want your extra fields to be sent in your order confirmation e-mail here is how I was able to get this done:

1. In the file: includes/classes/order.php around line: #946 you will see this code:

//intro area
$email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
$this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n" .
EMAIL_TEXT_INVOICE_URL . ' ' . zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL', false) . "\n\n";
$html_msg['EMAIL_TEXT_HEADER'] = EMAIL_TEXT_HEADER;
$html_msg['EMAIL_TEXT_FROM'] = EMAIL_TEXT_FROM;

2a. Right after this line:
$this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .

2b. Add the extra fields you want to show in this format. My lines of coding look like this:
'Shipping to a Business or a Residence? '.$extra_field->fields['customers_extrafield']. "\n\n" .
'Chapter Letters: '.$extra_field->fields['customers_extrafield2']. "\n\n" .
'Chapter City and State: '.$extra_field->fields['customers_extrafield3']. "\n\n" .

*There are 2 items above in each line you need to make sure match your settings:
In the above coding: Change the text that looks like this: 'Chapter Letters: ' to 'YOUR TEXT OF CHOICE' This text is static so whatever you put in here will show in the e-mail, exactly ast you put it here.
In the above coding: ['customers_extrafield2'] make sure this matches the field you want to display. This information will be taken from the extra field of the customer and put into the e-mail dynamically.

***Examples: **
Shipping to a Business or Residence? Business
Chapter City and State: Ohama, Nebraska

**So now my coding looks like this:
**
//intro area
$email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
$this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
'Shipping to a Business or a Residence? '.$extra_field->fields['customers_extrafield']. "\n\n" .
'Chapter Letters: '.$extra_field->fields['customers_extrafield2']. "\n\n" .
'Chapter City and State: '.$extra_field->fields['customers_extrafield3']. "\n\n" .

EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n" .
EMAIL_TEXT_INVOICE_URL . ' ' . zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL', false) . "\n\n";
$html_msg['EMAIL_TEXT_HEADER'] = EMAIL_TEXT_HEADER;
$html_msg['EMAIL_TEXT_FROM'] = EMAIL_TEXT_FROM;

I was not able to get the single spacing issue resolved, so I just left it as double spacing. I experimented with the "\n" instead of: "\n\n" which according to what I read in a php forum is supposed to single space, but it never worked for me in the e-mail. So I just went back.

This will send your extra fields in the order confirmation e-mail only. I still needed this to go out in this e-mail but it would have been nice to get it into the order as well. A module for extra fields to display in orders and e-mails would be very nice for sure. Or at least more flexiblity in listing fields during signup would also help. Hope this helps others.

20 Jan 2014, 7:20 PM
#29
jimmyv avatar

jimmyv

Zen Follower

Join Date:
Feb 2008
Location:
Philadelphia
Posts:
292
Plugin Contributions:
2

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

I am doing exactly as described here and I get a space in the email which is blank. I get no errors and no display.

I have looked at possible locations for the global call top is line 940 in order.php

'</td></tr>' . "\n";

//extra fields addition
global $db;
$extra_query ="SELECT customers_extrafield, customers_extrafield2, customers_extrafield3 from ".TABLE_CUSTOMERS." WHERE customers_id = '".$_SESSION['customer_id'] ."'";
$extra_field = $db->Execute($extra_query);

//end extra fields

}

$order_total_modules->apply_credit();//ICW ADDED FOR CREDIT CLASS SYSTEM
$this->notify('NOTIFY_ORDER_AFTER_ORDER_CREATE_ADD_PRODUCTS');

}

If I add in the "ECHO" statement listed it throws an error plus it freezes on checkout saying the echo statement

[20-Jan-2014 11:49:37] PHP Warning: Cannot modify header information - headers already sent by (output started at /home1/includes/classes/order.php:953) in /home1/includes/functions/functions_general.php on line 45

So I removed that but it still doesn't work.

23 Jan 2014, 12:54 AM
#30
jimmyv avatar

jimmyv

Zen Follower

Join Date:
Feb 2008
Location:
Philadelphia
Posts:
292
Plugin Contributions:
2

Re: Adding extra fields to admin copy of order confirmation email, and orders area.

The stupid things always get you.

It goes here and you remove the echo statement noted in solution above.

//extra fields addition
global $db;
$extra_query ="SELECT customers_extrafield, customers_extrafield2, customers_extrafield3 from ".TABLE_CUSTOMERS." WHERE customers_id = '".$_SESSION['customer_id'] ."'";
$extra_field = $db->Execute($extra_query);
$extra_field->fields['customers_id'];

// lets start with the email confirmation