WooCommerce Coupons Customer Info

In this tutorial I will show you how to include customers details (name or email address) next to WooCommerce Coupons under the admin interface in WooCommerce so that you can see who used coupons with a purchase.

 

For the newer WooCommerce Versions like 2.3.5:

These are the locations of where you need to copy and past the two pieces of code that you will find below.

  1. Theme’s function.php file located at ROOT/wp-content/themes/YOURTHEME/function.php
  2. WooCommerce’s class-wc-admin-cpt-shop_coupon.php located at ROOT/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php

 

For a Older WooCommerce Version:

These are the locations of where you need to copy and past the two pieces of code that you will find below.

  1. Theme’s function.php file located at ROOT/wp-content/themes/YOURTHEME/function.php
  2. WooCommerce’s class-wc-admin-cpt-shop_coupon.php located at ROOT/wp-content/plugins/woocommerce/includes/admin/post-types/class-wc-admin-cpt-shop_coupon.php

 

WooCommerce Coupons Code PART 1

In your function.php file located under your theme copy & past the following near the bottom before the closing php sign “?>” sign.:

Code part 1:

In this file above, if you look near the end you will see two lines of code.:

Sample 1 : echo $resultusername[0]->user_email . “<br/><br/>”;
Sample 2 : echo $resultusername[0]->user_nicename . “<br/><br/>”;

These will determine what values will show and from your selection, either show the user name or email address. Just commend ” // “the line out as per code above for the ones that you do not want to be displayed.

Sample 1:

WooCommerce Coupons Names

 

Sample 2:

WooCommerce Coupons Names

 

WooCommerce Coupons Code Part 2

Now for the second part. You need to insert the following code into one of WooCommerce class files. This file will probably be overwritten with the next WooCommerce update so you would need to add it back after each update to WooCommerce. Unfortunately there is no hook available to hook this piece of code into WooCommerce Core like with the code above.  With the never WooCommerce versions there is hooks added to the constructor of the class file. So you would be able to add all the code to the themes function.php file or in a separate extension plugin! The tutorial below requires a hardcoded method.

Code part 2:

InROOT/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php around line 130 (function: shop_coupon_columns) you can insert the code (above) after “Expiry date”.

The “customer” column name(complete line of code) you can move up in the hierarchy if you want to reposition the column name in admin.

then…

InROOT/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-post-types.php around line 448 (function: render_shop_coupon_columns) you can insert the code (above) after “case description”.

Hope this tutorial helped you in explaining how to add customer names or email address to the admin coupons fields so that you can know what users used coupons with a purchase. Let me know what you think?