How to create custom plugin for customised messages in checkout flow of  WooCommerce

In many cases, there will be requirement for showing some customised messages in Woo commerce checkout flow. Here we are discussing about how to create a custom plugin for displaying customised messages in checkout  and purchase success pages.

After installing our custom plugin,  checkout and checkout success page will show below messages.

First Create a folder called dn-check-out-validation in path wp-contents/plugins/

And create a file dn-custom-checkout.php

Add meta data like your plugin name and other details as below.

* Plugin Name: DN Check out plugin
* Plugin URI:
* Description: A plugin custom checkout Email validation
* Author:
* Author URI:
* Version: 1.0

On plugin loaded action,   call function dn_checkout_init where we are calling woocommerce check out actions  for displaying messages.

add_action( ‘plugins_loaded’, ‘dn_checkout_init’  );

We have to implement dn_checkout_init function as provided below.

if ( ! function_exists( 'dn_checkout_init' ) ) {
    function dn_checkout_init() {
          // check for woocommerce enabled or not
         if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
           // Yes, WooCommerce is enabled
         add_action( 'woocommerce_before_thankyou', 'dn_custom_checkout_success_message_after_payment'  );
         add_action( 'woocommerce_before_checkout_form', 'dn_custom_checkout_form_msg'  );
       } else {
         // WooCommerce is NOT enabled!

First check for woo commerce plugin enabled or not, then add below actions.

add_action( 'woocommerce_before_thankyou', 'dn_custom_checkout_success_message_after_payment'  );
         add_action( 'woocommerce_before_checkout_form', 'dn_custom_checkout_form_msg'  );

Function ‘dn_custom_checkout_form_msg’ is for showing a message on top of checkout form. Implementation is provided below.

// message above check out form
   if ( ! function_exists( 'dn_custom_checkout_form_msg' ) ) {
     function dn_custom_checkout_form_msg() {
         $message = "Please Provide valid billing email address. Purchased source code will be send to this email id!";
         wc_print_notice( esc_html($message), 'success' );

Below function display message after purchase  completed.

// message after purchase
   if ( ! function_exists( 'dn_custom_checkout_success_message_after_payment' ) ) {

             function dn_custom_checkout_success_message_after_payment( ){
                 wc_print_notice( __("You will recieve the purchased product in your Billing email shortly.If you are not recieving mail try again add to cart and purchase or contact", "woocommerce"), "success" );

You can download complete source code of this plugin here.

Get Free E-book
Get a free Ebook on Drupal 8 -theme tutorial
I agree to have my personal information transfered to MailChimp ( more information )
if you like this article Buy me a Coffee this will be an ispiration for me to write articles like this.