WooCommerce: Add New Report Tab

I have a project for a school. The seats in the class are sold as variable WooCommerce products and student info is captured at checkout. I want to put a new tab in the Reports section of WooCommerce to store all of the rosters. I don’t want to just put a new report on an existing tab. I have been searching around for how to do this for a full day.

Here is where I’ve gotten on my own. No idea if this is right or not.

When I dug into WC I found a filter called “woocommerce_admin_reports” that allows you to modify the values of an array called $reports. The filter is in this file:

wp-contentpluginswoocommerceincludesadminclass-wc-admin-reports.php

This seemed like the right place to start, but one of the values is the callback which seems to use a get_report() to pull the correct file. When I look at get_report() it seems to be building a string and then pulling the report from wp-contentpluginswoocommerceincludesadminreports.

public static function get_report( $name ) {
$name = sanitize_title( str_replace( ‘_’, ‘-‘, $name ) );
$class = ‘WC_Report_’ . str_replace( ‘-‘, ‘_’, $name );

include_once apply_filters( ‘wc_admin_reports_path’, ‘reports/class-wc-report-‘ . $name . ‘.php’, $name, $class );

if ( ! class_exists( $class ) ) {
return;
}

$report = new $class();
$report->output_report();
}

So, I simply copy/pasted a report and renamed it to:

wp-contentpluginswoocommerceincludesadminreportsclass-wc-report-rosters.php

But all I get is a list of errors from all over the place:

Notice: Undefined variable: reports in reports in C:xampphtdocseelewp-contentthemeseele-childfunctions.php on line 1271

Notice: Undefined offset: 0 in C:xampphtdocseelewp-includesplugin.php on line 897

Notice: Undefined offset: 0 in C:xampphtdocseelewp-includesplugin.php on line 915

Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in C:xampphtdocseelewp-includesclass-wp-hook.php on line 286

Warning: Invalid argument supplied for foreach() in C:xampphtdocseelewp-contentpluginswoocommerceincludesadminclass-wc-admin-reports.php on line 146

Warning: array_keys() expects parameter 1 to be array, null given in C:xampphtdocseelewp-contentpluginswoocommerceincludesadminclass-wc-admin-reports.php on line 31

Warning: array_keys() expects parameter 1 to be array, null given in C:xampphtdocseelewp-contentpluginswoocommerceincludesadminclass-wc-admin-reports.php on line 33

Warning: current() expects parameter 1 to be array, null given in C:xampphtdocseelewp-contentpluginswoocommerceincludesadminclass-wc-admin-reports.php on line 33

Warning: Invalid argument supplied for foreach() in C:xampphtdocseelewp-contentpluginswoocommerceincludesadminviewshtml-admin-page-reports.php on line 14

Here is the function I put in functions.php to try to get this to work. Commenting out the add_filter() line removes all of the errors so I know all of the errors are from this effort.

function eele_add_wc_reports( $reports ){

$reports[‘rosters’] = array(
‘title’ => __( ‘Rosters’, ‘woocommerce’ ),
‘reports’ => array(
‘rosters’ => array(
‘title’ => __( ‘Rosters’, ‘woocommerce’ ),
‘description’ => ”,
‘hide_title’ => true,
‘callback’ => array( __CLASS__, ‘get_report’ ),
),
),
);
return $reports;
}
add_filter( ‘woocommerce_admin_reports’, $reports );

Anyway, I know this is long. If you made it this far, thanks for taking the time. If there is a tutorial or something out there I have missed I’m more than happy to take a look. All of my searching has been made harder by the fact that lots of people want to know how to add a tab on the front end so I get lots of results for that kind of thing.

Please let me know if you have any questions.

Thanks,

Swani

Read more here:: WooCommerce: Add New Report Tab

Leave a Reply

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