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-content\plugins\woocommerce\includes\admin\class-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-content\plugins\woocommerce\includes\admin\reports.

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-content\plugins\woocommerce\includes\admin\reports\class-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:\xampp\htdocs\eele\wp-content\themes\eele-child\functions.php on line 1271

Notice: Undefined offset: 0 in C:\xampp\htdocs\eele\wp-includes\plugin.php on line 897

Notice: Undefined offset: 0 in C:\xampp\htdocs\eele\wp-includes\plugin.php on line 915

Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in C:\xampp\htdocs\eele\wp-includes\class-wp-hook.php on line 286

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\eele\wp-content\plugins\woocommerce\includes\admin\class-wc-admin-reports.php on line 146

Warning: array_keys() expects parameter 1 to be array, null given in C:\xampp\htdocs\eele\wp-content\plugins\woocommerce\includes\admin\class-wc-admin-reports.php on line 31

Warning: array_keys() expects parameter 1 to be array, null given in C:\xampp\htdocs\eele\wp-content\plugins\woocommerce\includes\admin\class-wc-admin-reports.php on line 33

Warning: current() expects parameter 1 to be array, null given in C:\xampp\htdocs\eele\wp-content\plugins\woocommerce\includes\admin\class-wc-admin-reports.php on line 33

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\eele\wp-content\plugins\woocommerce\includes\admin\views\html-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

1 Answer
1

add_filter('woocommerce_admin_reports','custom_tab');

function custom_tab($reports)
{
    $reports['custom_tab']= array(      
        'title'=>__('Custom Reports','woocommerce'),    
        'description'=> 'WooCommerce Orders Listing Here...',
        'hide_title'=> true,     
        'callback'=>array('wc_admin_orders_customers', 'display_orders_list_cusotomers')
    );
    return $reports;
}

Leave a Reply

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