Identify Who Added a Coupon in WooCommerce

By default, WooCommerce doesn’t log the user who adds a coupon. But you can enable this using a simple code tweak to track and display the coupon’s creator.

Step 1: Open your theme’s functions.php or a custom plugin file.

Step 2: Add the below code snippet:

// Save the creator ID
function save_coupon_creator($post_id) {
    $user_id = get_current_user_id();
    update_post_meta($post_id, 'coupon_creator', $user_id);
}
add_action('woocommerce_new_coupon', 'save_coupon_creator');

// Show creator on coupon edit
function display_coupon_creator($coupon) {
    $creator_id = get_post_meta($coupon->get_id(), 'coupon_creator', true);
    if ($creator_id) {
        $name = get_the_author_meta('display_name', $creator_id);
        echo 'Coupon Creator: ' . $name . ''; 
    } 
} 
add_action('woocommerce_coupon_options_usage', 'display_coupon_creator');

To make this visible in your coupon list table, follow these steps:

Step 1: Add this code to your theme/plugin:

// Add "Creator" column
function add_coupon_creator_column($columns) {
    $columns['coupon_creator'] = __('Coupon Creator', 'domain');
    return $columns;
}
add_filter('manage_edit-shop_coupon_columns', 'add_coupon_creator_column');

// Display name
function display_coupon_creator_column($column, $coupon_id) {
    if ($column === 'coupon_creator') {
        $id = get_post_meta($coupon_id, 'coupon_creator', true);
        echo $id ? get_the_author_meta('display_name', $id) : '-';
    }
}
add_action('manage_shop_coupon_posts_custom_column', 'display_coupon_creator_column', 10, 2);

// Make sortable
function make_coupon_creator_column_sortable($columns) {
    $columns['coupon_creator'] = 'coupon_creator';
    return $columns;
}
add_filter('manage_edit-shop_coupon_sortable_columns', 'make_coupon_creator_column_sortable');

// Add sorting logic
function modify_coupon_creator_column_sorting($query) {
    if (is_admin() && $query->is_main_query() && $query->get('orderby') === 'coupon_creator') {
        $query->set('meta_key', 'coupon_creator');
        $query->set('orderby', 'meta_value_num');
    }
}
add_action('pre_get_posts', 'modify_coupon_creator_column_sorting');

Now, your WooCommerce admin area shows and sorts coupons by their creator — helpful for accountability and user tracking.

 

Leave a Comment

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

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.