Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

WooCommerce Custom Emails based on Payment Gateway

One of the most important things for an online store to flourish is to create a sense of trustworthiness with the customers. There are a lot of ways to do so. One easy and simple way is to send emails to the buyers with details like the payment type (cash/ credit card/ cheque) and the store name.

Sending custom messages to your customers in the email can also help you with your sponsors. For example, you can send emails to the buyers who used their credit card and make them feel much more prioritized.

Our team at Themelocation is comprised of WordPress developers of high expertise

  • We can maintain, support and manage your single, or all your clients, website with dedication
  • Our skills are at your disposal.

Book a Call

In this tutorial, adding this functionality will be covered. First of all, you will have to paste the code below to the Theme Functions section.

Just go to Dashboard > Appearance > Theme Editor > Theme Functions and add the following code to the end of the existing code and click Update File.

[codesyntax lang=”php”]

add_action( 'woocommerce_thankyou', 'wc_cheque_payment_method_email_notification', 10, 1 );
function wc_cheque_payment_method_email_notification( $order_id ) {
    if ( ! $order_id ) return;

    $order = wc_get_order( $order_id );

    $user_complete_name_and_email = $order->billing_first_name . ' ' . $order->billing_last_name . ' <' . $order->billing_email . '>';
    $to = $user_complete_name_and_email;

    // ==> Complete here with the Shop name and email <==
    $headers = 'From: Shop Name <name@email.com>' . "\r\n";

    // Sending a custom email when 'cheque' is the payment method.
    if ( get_post_meta($order->id, '_payment_method', true) == 'cod' ) {
        $subject = 'your subject';
        $message = 'your message goes in here';
    }
    // Sending a custom email when 'Cash on delivery' is the payment method.
    elseif ( get_post_meta($order->id, '_payment_method', true) == 'cheque' ) {
        $subject = 'your subject';
        $message = 'your message goes in here';
    }
    // Sending a custom email when 'Western Union' is the payment method.
    else {
        $subject = 'your subject';
        $message = 'your message goes in here';
    }
    if( $subject & $message) {
        wp_mail($to, $subject, $message, $headers );
    }
}

[/codesyntax]

 

Secondly, you need to replace ‘Shop name < name@email.com >’ with the name and email address of your store. Next, you need to replace the line ‘Your message goes in here’ with some custom message of your choice.

And there you go, you are all set to send custom emails to your customers according to their payment method.

Let us know your thoughts in the comments section below.

 

Waqas

I hope you enjoy reading this blog post. If you want my team to do WooCommerce Maintenance for you, click here.

Leave a Comment

Your email address will not be published. Required fields are marked *