admin管理员组文章数量:1415484
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
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
Share Improve this question asked Oct 11, 2018 at 13:17 swaniswani 313 bronze badges 2 |1 Answer
Reset to default 2add_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;
}
本文标签: adminWooCommerce Add New Report Tab
版权声明:本文标题:admin - WooCommerce: Add New Report Tab 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745183201a2646560.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_filter( 'woocommerce_admin_reports', 'eele_add_wc_reports' );
I guess. Let us know is that works. – Pim Commented Oct 11, 2018 at 13:25