WC_REST_Report_Coupons_Totals_Controller::get_reports
Get reports list.
Метод класса: WC_REST_Report_Coupons_Totals_Controller{}
Хуков нет.
Возвращает
array.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_reports();
Список изменений
| С версии 3.5.0 | Введена. |
Код WC_REST_Report_Coupons_Totals_Controller::get_reports() WC REST Report Coupons Totals Controller::get reports WC 11.3.0
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;
}