In Woocommerce, there is already a built-in way to add recipients to the "New Order" , "Failed", and "Cancelled" emails, but for some reason, the "Customer invoice / Order details" don't allow any recipient other than the customer.
There is a simple plugin that allows for that, but it is very limited in features.
Any guidance for how to add recipients to this email?
I plan to use a Code Snippet to call the hook/filter/action and then tell it explicitly which email addresses to use. I intend to write the script so that whatever user initiates the action, will be CC'ed on that email. Presumably the same function that can do the first part of my question can help me to check current user and will grab their email address.
Any help is appreciated
I don't know what buil-in functionality are you talking about. But you can use the below filter to add recipients to the invoice email. You don't need any plugin, just use this below code snippet in your active theme/child theme functions.php
add_filter("woocommerce_email_recipient_customer_invoice", "add_recipient_to_email", 10, 2);
function add_recipient_to_email( $recipients, $object ){
$new_email = "newemail#domain.com"; //New email Id
$recipients = $recipients.','.$new_email;
return $recipients;
}
Related
I have added a custom shipping option which works great, however duplicate emails are sent - my custom shipping new order email and the standard admin new order email.
In WooCommerce > Settings > Email I have added a new option for my custom shipping and added recipients and so on. What I think I need to do now is put a condition in to the Admin New Order section, something along the lines of..
if(shipping method == 'Custom Shipping')
return; // this can just bail out as a custom shipping email is being sent
I think this will stop the standard new order email being sent if the order uses Custom Shipping.
Can anyone give me guidance on how I can implement this? Do I put code in to the admin-new-order.php file with this if statement? Thank you
You could remove the standard mail actions: https://docs.woocommerce.com/document/unhookremove-woocommerce-emails/
And then intercept the order_status_changed hook to trigger your mail depending on conditions (like the shipping method): https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html
function your_function($id)
{
$order = wc_get_order($id);
if (!empty($order) && $order->get_shipping_method() === 'Custom Shipping') {
do_action('woocommerce_before_resend_order_emails', $order, 'email_name');
// prepare your email
do_action('woocommerce_after_resend_order_email', $order, 'email_name');
}
}
add_action('woocommerce_order_status_changed', 'your_function');
I'm creating a page in which you submit a Contact Form 7 to the email based on what email is added to the job_email field via my Advanced Custom Fields.
I have attempted to add the form via the PHP shortcode like this
[email* dynamic-email class:email-address placeholder "Email Address*"]
echo do_shortcode('[contact-form-7 id="234" title="Dynamic Submit CV" dynamic-email="'.get_field( 'job_email' ).'"]' );
The fields all display correctly, and upon submitting the email successfully, the email never receives the form. Meaning I am totally missing something here.
If I understand correctly, what you are after is send a notification with the entry details to the email address inputted on the job_email field.
If so, what you want to do is to set up an email on the email tab and in the To: setting put [job_email].
Update
As you stated in the comment, the email has to be the one set in the backend. You can guarantee the email notification to be sent to the ACF-based email via hooks, specifically the wpcf7_mail_components hook.
function so57013385_mail_components( $components, $number ) {
$job_mail = get_field( ... );
$components['recipient'] = (array) $components['recipient'];
$components['recipient'][] = $job_mail;
return $components;
};
add_filter( 'wpcf7_mail_components', 'so57013385_mail_components', 10, 2 );
Note: I'm casting the $components['recipient'] variable to array just to make sure the email is appended correctly, as this parameter is passed directly to wp_mail(), which can receive a string or an array. Also, you might need to add more validations on the form ID, sanitization, etc. The above code is not tested.
Let me start by saying that I have no code yet, and have researched this without finding anything. If anyone could point me in the right direction, it would be great.
Basically, I want to preferably use a code functions.php that checks the payment method of a WooCommerce order and sends the standard new order email to a specific email address. This address could be hardcoded to make it more simple.
What I want to achieve is that every time an order is placed with Stripe as the payment method, the standard new order email is sent to this additional email address while also being sent to the specified address in the WoocCommerce settings. If any other payment method is used, nothing should happen besides the normal new order email getting sent.
I would be very thankful if anyone could point me in the right direction, but please keep in mind that I am not a super-coder by any means.
Try the following code that will add an additional recipient to "New Order" email for stripe payment gateway:
add_filter( 'woocommerce_email_recipient_new_order', 'new_order_additional_recipients', 20, 2 );
function new_order_additional_recipients( $recipient, $order ) {
if ( ! is_a( $order, 'WC_Order' ) )
return $recipient;
// Set Below your additional email adresses in the arrayy
$emails = array('name1#domain.com');
$emails = implode(',', $emails);
// Adding recipients conditionally
if ( 'stripe' == $order->get_payment_method() )
$recipient .= ',' . $emails;
return $recipient;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
In WordPress, I have custom registration site for new users. Upon registration, there is an optional checkbox to subscribe to our newsletter. As far as I understand it, it adds the value of the checkbox to the user_meta table (the whole thing has been coded by a company in India, which I woould very much prefer to not involve again, since they delayed their work time and time again and didn't do good work after all).
The corresponding code snippet in my child theme's functions.php looks like this:
<?php echo '<div class="form-row form-row-wide">
<input type="checkbox" name="inter_offers" value="yes"> '; _e('I would like to subscribe to the Kurth Electronic newsletter.','kurth-child'); echo '<br></div>';
return $fields; ?>
add_action('woocommerce_created_customer','adding_extra_reg_fields');
function adding_extra_reg_fields($user_id) {
extract($_POST);
update_user_meta($user_id, 'billing_inter_offers',$inter_offers);
} ?>
(I have left out lines irrelevant to this issue.)
Now, this value is saved internally, but not displayed to me. I would like to show the value in an E-Mail or notification generated by WordPress when the user completes registration, so that we can manually add them to our newsletter list whenever someone chooses to subscribe to the newsletter. The problem is that I only have a limited knowledge of PHP and I don't know where to start.
I should also note that this is not done via the standard WorPress registration form, but by a WooCommerce registration form (I have disabled the standard WordPress registration for security reasons).
I tried using the "Better Notifications" plugin (https://wordpress.org/plugins/bnfw/) for custom notifications whenever a new user completes their registration, but it ignores any php code that I add to the custom notifications body to display the user_meta data.
Any help would be appreciated.
Because the registration is done via woocomerce you may have to look for a notification PlugIN that works with woocomerce, the one you have may just work properly with wordpress core version!
You also could generate a mail via php in the function, so that you get a message with the user mail adress, but i think without php knowledge it is not that easy to use the built in php mailer... (You may need an api there!)
But wouldn't it be better to automatically sign them into your newsletter software? For example for Mailchimp or other systems like that there are quite good wordpress plugins!
You may also be able to include the forms of these PlugIns in your registration form, but without a closer look at this woocomerce registration i can't tell for sure!
I think this will do the trick, it will notify you every time a new user is created and also tell you if they subscribed or not.
function new_customer_registered_send_email_admin($user_login, $user_email) {
ob_start();
do_action('woocommerce_email_header', 'New customer registered');
$email_header = ob_get_clean();
ob_start();
do_action('woocommerce_email_footer');
$email_footer = ob_get_clean();
$user = get_user_by( 'email', $user_email );
$subscribed = get_user_meta( $user->ID, 'billing_inter_offers', true );
woocommerce_mail(
get_bloginfo('admin_email'),
get_bloginfo('name').' - New customer registered',
$email_header.'<p>The user '.esc_html( $user_login ).' created an account ' . ( $subscribed ? ' and subscribed to the newsletter.' : '.' ) . '<br>Email:'.esc_html( $user_email ).'</p>'.$email_footer
);
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin', 10, 2);
I ended up using the plugin amr users to generate a userlist of all users who had a certain metadata tag set to a certain value (in my case, if they want to recieve a newsletter - the previous developers never bothered to make the data actually readable without extra effort). It is a little clunky to use and not what I originally intended, but it got the job done.
Can Magento send email to admin, when user place order ?
It is necessary to send information about placed order to admin’s email
admin notification should have another template
Yes it can you can set all orders to be bcc -d from
system > configuration > sales > sales emails
I hacked core code to do this on my Magento install. The 1st level of properly editing core files is to override them in app/code/local somewhere...
Make your admin_order_notify_email template, save it, and note its ID. Mine was 8. Oh, and to get access to the customer's email address, use this code in the template: {{var order.getCustomerEmail()}}. This vexed me for months. :P My next trick will be to barcode the order number in the admin order notification email.
Now, open the file app/code/core/Mage/Sales/Model/Order.php
<?
$mailTemplate = Mage::getModel('core/email_template');
/* #var $mailTemplate Mage_Core_Model_Email_Template */
//chris near line 854: $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
$copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $this->getStoreId());
if ($copyTo && $copyMethod == 'bcc') {
foreach ($copyTo as $email) {
//chris $mailTemplate->addBcc($email);
}
}
//chris near line 900: added this to use admin email template for new orders. Note it is hard coded to template 8, which I added
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$this->getStoreId()))
->sendTransactional(
8,
Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $this->getStoreId()),
$this->_getEmails(self::XML_PATH_EMAIL_COPY_TO),
"MyBusinessName Orders",
array(
'order' => $this,
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlock->toHtml(),
)
);
?>
The crm4ecommerce extension is encrypted, and cannot be audited for security.
Another free option is Inchoo Admin Order Notifier.
"Magento extension that enables email notifications towards various emails when customer places the order. Useful when you want your personell notified that some customer just placed the order. Supports transactional email."
From: https://github.com/ajzele/Inchoo_AdminOrderNotifier