WC_REST_Report_Coupons_Totals_Controller::get_reports
Get reports list.
Method of the class: WC_REST_Report_Coupons_Totals_Controller{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->get_reports();
Changelog
| Since 3.5.0 | Introduced. |
WC_REST_Report_Coupons_Totals_Controller::get_reports() WC REST Report Coupons Totals Controller::get reports code WC 10.4.3
protected function get_reports() {
global $wpdb;
$data = get_transient( 'rest_api_coupons_type_count' );
if ( false !== $data ) {
return $data;
}
$types = wc_get_coupon_types();
$data = array();
foreach ( $types as $slug => $name ) {
$results = $wpdb->get_results(
$wpdb->prepare( "
SELECT count(meta_id) AS total
FROM $wpdb->postmeta
WHERE meta_key = 'discount_type'
AND meta_value = %s
", $slug )
);
$total = isset( $results[0] ) ? (int) $results[0]->total : 0;
$data[] = array(
'slug' => $slug,
'name' => $name,
'total' => $total,
);
}
set_transient( 'rest_api_coupons_type_count', $data, YEAR_IN_SECONDS );
return $data;
}