I'm faced with a little problem.
I need to send the Customer Invoice / Order Details email automatically when an order is completed.
I haven't found any action or filter to apply in this case an the internet is not useful. Has anyone an idea how to send this email when the order status switches?
Best regards!
You can use woocommerce_order_status_completed hook and WC_Email_Customer_Invoice
add_action( 'woocommerce_order_status_completed', 'mysite_woocommerce_order_status_completed', 10, 1);
function mysite_woocommerce_order_status_completed( $order_id ) {
// Send invoice email to customer
//use order ID as trigger value
WC()->mailer()->emails['WC_Email_Customer_Invoice']->trigger($order_id);
}
Related
I need WooCommerce to send specific emails from the customer's email address rather than the admin email address.
Background:
I'm setting up a paid support service which uses WooCommerce for payments and bbPress as a ticketing system.
A user orders a service product through WooCommerce and a new WooCommerce order is created. The order needs to then populate a ticketing system and my workaround is to have the 'New order' email sent to an email inbox and then pulled in by the ticketing system. Obviously this is not perfect and introduces a point of failure but it's fine for now.
The problem is that the new order email is sent from the WooCommerce admin email address, so the new ticket is associated with that account rather than the account of the user who created the order.
So I need the email from address to be the address of the user that submitted the order.
Is this possible with a hook?
in woocommerce/includes/class-wc-emails.php we have the following:
public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = '' ) {
// Send.
$email = new WC_Email();
return $email->send( $to, $subject, $message, $headers, $attachments );
}
This doesn't include the sender, and as it's buried in a class, could it be overridden anyway?
Greatful for any pointers.
(PS I do appreciate there are issues with this approach, including emails being flagged as spam, but initially this will be manageable until I get a more robust system in place)
(PPS I'm aware there is an almost identical question but the links aren't working and relates to a very out of date WooCommerce)
That's impossible to send the email from your customer email address. You can only set the customer email to Reply-To in WP_Mail header.
In my experience, you should send another email to your sepcific email inbox, and skip the email sent by WooCommerce by default. Use this hook:
add_action('woocommerce_order_status_pending_to_processing', 'order_created_send_email');
function order_created_send_email($order_id, $order) {
$customer_email = $order->get_billing_email();
/* Code to send email with Reply-To: customer email */
}
I want to send e-mails to user account email and not to billing email in WooCommerce.
I only found that code but I think this is outdated and I also don't want to send 2 mails only one to customer user email.
Code here:
https://www.webdesign101.net/send-e-mails-user-account-email-billing-email-woocommerce/
Tried this code but outdated and also 2 mails instead of one going to user email.
And I didn't found the line in woocommerce/templates/email to change the header from billing_email to user_email.
I want so send emails from WooCommerce to user email not to billing email.
function wc_change_new_order_email_recipient($recipient, $order) {
global $woocommerce;
$user = $order->get_user();
$recipient[] = $user->user_email;
return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_new_order_email_recipient', 10, 2);
I use a custom status: Payment Due. Once an order gets the status Payment Due it will automatically trigger a email after 14 days reminding the customer to pay for their order.
Now when this customer tries to pay but it fails for whatever reason the order will get the status Cancelled.
But I need this order to get back to status Payment Due or something similar like Payment Failed.
So for particular statuses I would really like to remove the status Cancelled and Failed from applying when a customer fails to complete the payment and apply a other custom status in stead
The following hook did the trick:
add_action( 'woocommerce_order_status_reminder_to_failed',
'change_status_to_payment_required' , 10, 10 );
function change_status_to_payment_required( $order_id ) {
$order = wc_get_order($order_id);
$order->update_status( 'payment-required' );
}
I'm looking for a solution where we can disable woocommerce sending email notification when an order is done by a client from a specific customer group (user role).
I found answer about a situation what prevent sending email for a specific product-ID.
Disable WooCommerce email notification for specific product.
Maybe this could be possible for our 'problem' too?
Kind regards,
Kees
You can use the hook for any email and inside the callback function you can check if the user has a specific role
function change_new_order_email_recipient( $recipient, $order ) {
global $woocommerce;
$uid = $order->get_user_id();
$user_meta=get_userdata($uid);
$user_roles=$user_meta->roles;
if(in_array('customer', $user_roles)){ // Prevent email if user role is customer
$recipient ='';
}
return $recipient;
}
add_filter('woocommerce_email_recipient_customer_completed_order', 'change_new_order_email_recipient', 1, 2);
I have checked the code rapidly and is working
I tried to update user meta field after the checkout payment is successful. I tried keeping the following code in thankyou.php
update_user_meta($user->ID, '_uw_balance', $updated_balance);
Actually i'm using a wallet plugin called "User Wallet Credit System" and using the user wallet balance to get deducted in the total order amount. I'm able to deduct the wallet amount in order total but unable to update the wallet after the successful payment.
I'm using woocommerce for the checkout and everything. I need to how should i update the wallet amount after the transaction is processed.
Use woocommerce_thankyou being called after successful checkout.
you can play with order id,
add_action('woocommerce_thankyou', 'update_e_wallet', 11, 1);
function update_e_wallet($order_id) {
//do something...
}
also you can get user by order id
$order = new WC_Order( $order_id );
$user_id = $order->user_id;