Post by coldwellr » Thu May 17, 2018 10:36 pm

Hi. I'm using OpenCart 3.0.2.0.

I've added a customer custom field (a checkbox) in my checkout registration section. How do I get the value of that checkbox (if its been checked) to be included in my admin order email? I also want to show if the user has checked the 'newsletter' box in the admin email too.

I know I have to edit the following files:

Code: Select all

catalog/controller/mail/order.php

Code: Select all

catalog/view/theme/default/template/mail/order_alert.twig
My custom field is called 'Marketing Consent'. At the moment I'm trying this (which I know is wrong!!)

Code: Select all

if ($order_info['custom_field']) {
    $data['consent'] = $order_info['custom_field']['marketing_consent']; 
}
Can anyone give me some tips on the best way to pull that information out and include it in the admin order email?

Many thanks.

New member

Posts

Joined
Fri Nov 17, 2017 9:07 pm

Post by yodapt » Thu May 17, 2018 11:06 pm

Is that the only field you will ever have as custom field?

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by coldwellr » Mon May 21, 2018 4:36 pm

Hi. For now it's probably the only one yes. Are you thinking I should do a 'for each' loop in case I add more? At the moment yes, I'm just trying to get this checkbox and the newsletter checkbox included in the admin order email.

New member

Posts

Joined
Fri Nov 17, 2017 9:07 pm

Post by coldwellr » Fri May 25, 2018 4:37 pm

For info, I figured this out. In 'catalog/controller/mail/order.php' I added the following:

Code: Select all

$newsletter_query = $this->db->query("SELECT newsletter FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$order_info['customer_id'] ."'");
      	if($newsletter_query->num_rows) {
      		$data['newsletter'] = $newsletter_query->row['newsletter'];
      	}
and of course in 'catalog/view/theme/default/template/order_alert.twig I added the following:

Code: Select all

Newsletter Consent: {{ newsletter }}
Cheers.

New member

Posts

Joined
Fri Nov 17, 2017 9:07 pm
Who is online

Users browsing this forum: alanjones and 82 guests