class MyDataStore extends DataStore implements DataStoreInterface { * /** Cache identifier, used by the `DataStore` class to handle caching for you. */ * protected $cache_key = 'my_thing'; * /** Data store context used to pass to filters. */ * protected $context = 'my_thing'; * /** Table used to get the data. */ * protected static $table_name = 'my_table'; * /** * * Method that overrides the `DataStore::get_noncached_data()` to return the report data. * * Will be called by `get_data` if there is no data in cache. * */ * public function get_noncached_data( $query ) { * // Do your magic. * * // Then return your data in conforming object structure. * return (object) array( * 'data' => $product_data, * 'total' => 1, * 'page_no' => 1, * 'pages' => 1, * ); * } * } *
add_filter( 'woocommerce_data_stores', function( $stores ) { * $stores['reports/my-thing'] = 'MyExtension\Admin\Analytics\Rest_API\MyDataStore'; * } ); *