WooCommerce pdf attachment to custom email is not working - email

I am using WooCommerce order status manager plugin for custom order statuses and emails notifications. I have created custom status for paid orders via card pay - card-on-hold.
I have also created custom email which will be triggered when statuses will change from receivet to card-on-hold.
my code is:
add_filter( 'woocommerce_email_attachments', 'attach_manual_pdf_to_email', 10, 3);
function attach_manual_pdf_to_email ( $attachments, $status , $order ) {
$allowed_statuses = array( 'customer_processing_order', 'customer_on_hold_order', 'customer_order_status_email' );
if( isset( $status ) && in_array ( $status, $allowed_statuses ) ) {
$dokument = get_template_directory() . '/woocommerce/emails/attach.pdf';
$attachments = $dokument;
}
return $attachments;
}
Email Ids customer_processing_order and customer_on_hold_order works like a charm.
But customer_order_status_email which is php template for order status manager is not working. It is located in betheme/woocommerce/emails/customer-order-status-email.php and I did also try to move it to same locations where other templates are but that did not help.
Any idea how to make this working please?

okay i did find a solution:
i did use echo '<pre>'; print_r($email->id); echo '</pre>' in template of an email which printed me an email ID. i used this id in my allowed statuses and it is working now.

Related

Order tables in prestashop when should be it created?

When should actually an order must be created in PrestaShop, We integrated a local payment module which will redirect to there page and after entering card details and validating the payment it returns back , and it creates an order at that time.
My problem is that if the payment is declined , (or if I close the browser when the payment is processing in the payment page ) order is not created in the ps_order table but cart is created and if I query the bank with another WEB service the payment response is success for that cart_id and id_order is 0,
but I dont have an order or entry in ps_order table created in my ps_order table .How to cater this scenario?
Is it correct to create the order (insert into the order table )before payment processing and put current_state field as 3 status 3 means Processing in progress and change the current_state field if the payment is success or not.
select * from ps_orders
this is how the payemnt module does
if($reponseParameters[8]=='00000'){
// Update the Respose to the ps_networkonline_payment
$sql_response = " UPDATE `"._DB_PREFIX_."networkonline_payment` SET response = '".$text."' , `status` = '".$reponseParameters[4]."', error_code = '".$reponseParameters[8]."' WHERE order_id = '".$cart->id."' ";
Db::getInstance()->execute($sql_response);
// Create Order In prestashop pass the values to order-confrimation class
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $this->module->displayName, 'Transaction Reference: ' . $reponseParameters[5], array(), (int)$currency->id, false, $customer->secure_key);
// Update the ps_order_payment table to make the PrestaShop Payment success
$q_orders = 'SELECT `reference` FROM ' . _DB_PREFIX_ . 'orders WHERE `id_cart` = ' . (int) $cart->id;
if ($r_orders = Db::getInstance()->getRow($q_orders)){
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'order_payment` SET `transaction_id` = \'' . pSQL($reponseParameters[5]) . '\' , `card_brand` = \'' . pSQL($reponseParameters[7]) . '\' WHERE `order_reference` = \'' . pSQL($r_orders['reference']) . '\'');
}
Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
return;
}else{
$this->error = $reponseParameters[9];//$this->module->getErrorMessage($object->error_code);
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_ERROR'), $total, $this->module->displayName, $this->error, array(), (int)$currency->id, false, $customer->secure_key);
}
}else{
//fail
$this->error = $reponseParameters[9];//$this->module->getErrorMessage($object->error_code);
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_ERROR'), $total, $this->module->displayName, $this->error, array(), (int)$currency->id, false, $customer->secure_key);
}
}
What payments modules usually have is a way for the bank to query your website when your customers are redirected to their platform, this way the order is created on your side no matter what happens on their side (leaving you with a freshly created order with a state like "pending payment").
Then the order is updated on the customer's return to your website, by a call from the bank (be it with a status "blocked", "cancelled", or "payment accepted").

Woocommerce - Change order received text after redirecting from PayPal with IPN

I like to change the thank you page text in case the customer already paid via paypal.
Redirecting via PayPal works fine. Order status is "processing", ok.
But how can I change the thank you text on the redirecting page (https://www.example.com/checkout/order-received/)
I tried the following, with no success:
function my_update_order_status() {
$order = new WC_Order($order_id);
if ($order_status == 'processing')
echo 'NEW MESSAGE';
else
echo 'NOT PAID TEXT';
}
add_filter('woocommerce_thankyou_order_received_text', 'my_update_order_status', 10, 2);
There is an explanation on how to change the thank you page here:
https://wordpress.org/support/topic/how-to-edit-the-thank-youorder-received-page
If you don't wish to do any template modifying then you can include the order received function to adjust it. For example:
function isa_order_received_text( $text, $order ) {
$new = $text . ' All received and an email is on its way to you!.';
return $new;
}
add_filter('woocommerce_thankyou_order_received_text', 'isa_order_received_text', 10, 2 );
The above with add text to the current text output.

Making Register Plus Redux work with Nextend Google Connect

I'm trying to make two popular WordPress plug-ins work well together. Hopefully this question isn't too specific to my setup -- I think enough people use these plug-ins to make it a common issue.
I'm using Register Plus Redex (RPR) to require user registration to be accepted (by admin) before a user can log-in. Alone, this works fine.
I'm also using Nextend Google Connect (NGC) to allow users to log-in with Google. Those also need to be approved before they can log-in.
When NGC creates a new user in the database, it correctly has the "not activated" flag set. However, the user is still logged in. This allows them to see some blog pages that are protected by "Members Only" (another plug-in). I could maybe update Members Only or other areas to avoid this, but I would rather these users see the same behavior a normal user would see, one that just logs in with user/password, not Google. They get a nice "Your account has not been activated yet" message.
RPR has this code to authenticate, I think I need to use it from NGC some way:
public /*.object.*/ function rpr_authenticate( /*.object.*/ $user, /*.string.*/ $username, /*.string.*/ $password) {
if ( !empty($user) && !is_wp_error( $user ) ) {
if ( NULL !== get_role( 'rpr_unverified' ) && in_array( 'rpr_unverified', $user->roles ) ) {
return null;
}
}
return $user;
}
I think this is the section of NGC code I need to modify:
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($ID, true, $secure_cookie);
$user_info = get_userdata($ID);
do_action('wp_login', $user_info->user_login, $user_info);
do_action('nextend_google_user_logged_in', $ID, $u, $oauth2);
update_user_meta($ID, 'google_profile_picture', 'https://profiles.google.com/s2/photos/profile/' . $u['id']);
The NGC code uses what I think is a "hacked" method of log-in. It doesn't use any of the methods I have seen recommended online, like the new wp_signon or older wp_login functions.
Is what I'm trying to do a major project? If so, is there another combination of plug-ins (or a single one) that will handle the following:
Require users to be logged in to see any pages (what Members Only does)
Require admin to moderate/approve new users (what RPR does)
Support log-in via Facebook, Twitter, and Google (what the Nextend Connect plug-ins do)
Update:
I changed the NGC code to this, and now it doesn't log the user in, but it just leaves them on the log-in page with no error message. I'm not sure how I can add an error message to the default log-in page, everything I find online is related to custom log-in pages.
if ($ID) { // Login
$user_info = get_userdata($ID);
if ( !empty($user_info) && !is_wp_error( $user_info ) ) {
if ( NULL !== get_role( 'rpr_unverified' ) && in_array( 'rpr_unverified', $user_info->roles ) ) {
// TODO - How to add error message to log-in page?
return;
}
}
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($ID, true, $secure_cookie);
//
do_action('wp_login', $user_info->user_login, $user_info);
do_action('nextend_google_user_logged_in', $ID, $u, $oauth2);
update_user_meta($ID, 'google_profile_picture', 'https://profiles.google.com/s2/photos/profile/' . $u['id']);
}
I'm sure there is a better way to do this, one that will not be undone anytime I update the plug-in, but for now this works for me.
I updated nextend-google-connect.php, part of the Nextend Google Connect plug-in, and changed the Login code (starting around line 230 depending on your version) to this:
if ($ID) { // Login
$user_info = get_userdata($ID);
if ( !empty($user_info) && !is_wp_error( $user_info ) ) {
if ( NULL !== get_role( 'rpr_unverified' ) && in_array( 'rpr_unverified', $user_info->roles ) ) {
wp_redirect('wp-login.php?checkemail=registered');
exit;
}
}
$secure_cookie = is_ssl();
$secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
$auth_secure_cookie = $secure_cookie;
wp_set_auth_cookie($ID, true, $secure_cookie);
do_action('wp_login', $user_info->user_login, $user_info);
do_action('nextend_google_user_logged_in', $ID, $u, $oauth2);
update_user_meta($ID, 'google_profile_picture', 'https://profiles.google.com/s2/photos/profile/' . $u['id']);
}
By redirecting to that special URL, the Redux plug-in already has code to display a nice message to the user letting them know the admin needs to verify the account.

cakephp pre-fill email form with address

I have a list of email addresses on a page and I would like to add the functionality so that when an email address is clicked it opens up an email form with that email address already pre-filled in the recipient field. How can I do this?
This is the form I have already;
<?php echo $this->Form->create('Email', array('action'=>'email_send.php'));
echo $this->Form->input('email',array('label'=>'To: ')); //i want the email address i clicked on to be automatically placed here.
echo $this->Form->input('message',array('type'=>'textarea','label'=>'Message: '));
echo $this->Form->end('Send'); ?>
Also if anyone has any tips on how I'll structure the email_send.php file and the best way to pass variables and perform validation I could use a hand with that too.
In cake, you could achieve it a little like this.. obviously improvements can be made but it's an example:
EmailsController.php (controller)
function list_emails() {
$this->set('emails', $this->EmailModel->find('all', array('fields' =>
array('id', 'email'))));
}
list_emails.ctp (view)
echo '<ul>';
foreach($emails as $email) {
echo '<li>' . $this->Html->link('Email: ' . $email['EmailModel']['email'],
array('action'=>'process', $email['EmailModel']['id'])) . '</li>'; ?>
}
// generates a list of emails in the format:
// Email: foo#foo.com
echo '</ul>';
EmailsController.php (controller)
function process($email_id = null) {
if(!$email_id) {
$this->redirect(array('action'=>'show_emails')); // no id specified
}
// check if the form has been submit, otherwise, get the info for the view..
$this->EmailModel->id = $email_id;
$email = $this->EmailModel->read();
$this->set('email', $email);
}
and the information is now available to you in your process view.
// echo $this->Form->input('email',array('label'=>'To: ','value'=>$email['EmailModel']['email']));
but it's a lot of work really. And don't forget the value can be always be changed; making this a bit pointless
Try this code:
in controller
$this->set('email',$email); //$email is the mail address from database
in view
echo $this->Form->input('email',array('label'=>'To: ','value'=>$email));
or
you can put email in '$this->request->data' array it will automatically populate in view like this:
you should add this in your controller
$this->request->data['Email']['email'] = 'YOUR_EMAIL_FROM_DATABASE';

Triggering conversion tracking code on form submit

I have a PHP form that mail()s the form data on submit and then if successful returns them to the referring page (in other words keeping them on the same page as the form) and appends ?success=TRUE to the URL.
The question is, how would I implement the AdWords and Yahoo Search Marketing conversion code snippets to trigger only when the form is submitted? For functionality purposes, it is unfortunately not feasible to send them to another page on submit which would have been the easiest way to do it.
The relevant code from the form submit action that mails the results and sends them back to the homepage is below. I have a hunch it might be as simple as outputting the conversion tracking code snippets in the if statement at the end there but I'm not sure if that is correct or the syntax to properly do that.
if ( isset($_POST['sendContactEmail']) )
{
$fname = $_POST['posFName'];
$lname = $_POST['posLName'];
$phone = $_POST['posPhone'];
$email = $_POST['posEmail'];
$note = $_POST['posText'];
$to = $yourEmail;
$subject = $yourSubject;
$message = "From: $fname $lname\n\n Phone: $phone\n\n Email: $email\n\n Note: $note";
$headers = "From: ".cleanPosUrl($_POST['posFName']. " " .$_POST['posLName'])." \r\n";
$headers .= 'To: '.$yourName.' '."\r\n";
$mailit = mail($to,$subject,$message,$headers);
if ( #$mailit ) {
header('Location: '.$referringPage.'?success=true');
}
else {
header('Location: '.$referringPage.'?error=true');
}
}
Outputting it in the if-Statement would be a possibility, but the script you posted adds another way to do it as it redirects to the $referringPage - if the mail was successfully sent. And that's the only event you want to track a conversion.
So edit the code of $referringPage (the page that holds the form fields) and add:
<?php
if($_GET['success'] == 'true') {
echo "...";
}
?>
"..." ofcourse has to be replaced by the Adwords conversion Code Google gave you.
If you add it to your question, I could even add it to my answer.