Skip to content

Instantly share code, notes, and snippets.

@jdeeburke
Created July 30, 2018 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdeeburke/70851d3a48216ed03650197e28442bde to your computer and use it in GitHub Desktop.
Save jdeeburke/70851d3a48216ed03650197e28442bde to your computer and use it in GitHub Desktop.
Customer/Order CSV Export Custom Data Store Example
<?php
class Custom_CSV_Export_Data_Store extends WC_Customer_Order_CSV_Export_Data_Store {
/**
* Persists a single item.
*
* @param \WC_Customer_Order_XML_Export_Suite_Export $export the export object this item is a part of
* @param string $content the content to store
*/
public function store_item( $export, $content ) {
// store an item
}
/**
* Gets the file size of the given export in bytes.
*
* @param \WC_Customer_Order_XML_Export_Suite_Export $export the export object
* @return int file size in bytes
*/
public function get_file_size( $export ) {
// get the file size of this export in bytes. This is used in the
// response headers when downloading an export, so the client browser
// can accurately report download progress.
}
/**
* Deletes any persisted data for the specified export.
*
* @param \WC_Customer_Order_XML_Export_Suite_Export $export the export object
*/
public function delete_export( $export ) {
// delete the export
}
/**
* Gets the contents of an export in a single variable.
*
* @param \WC_Customer_Order_XML_Export_Suite_Export $export the export object
* @return string|null the output of the export or null if not found
*/
public function get_output( $export ) {
// return a string containing the full contents of the export
}
/**
* Gets a streamable resource for the export file.
*
* @param \WC_Customer_Order_XML_Export_Suite_Export $export the export object
* @return resource|false the file stream or false if unable to get file stream
*/
public function get_file_stream( $export ) {
// return a PHP resource containing the export that can be streamed.
}
/**
* Streams data to the given file resource.
*
* @param \WC_Customer_Order_XML_Export_Suite_Export $export the export object to stream
* @param resource $resource the file pointer resource to stream the export to
*/
public function stream_output( $export, $resource ) {
// stream the export to a given resource stream.
}
/**
* Allows the data store to add arguments to new jobs.
*
* @param array $args arguments for a new job to be created from
* @return array additional job arguments to add
*/
public function get_job_args( $args ) { return array(); }
/**
* Prepares content for storage.
*
* @param string $content the content to be stored
* @return string the content after it has been prepared for storage
*/
protected function prepare_content_for_storage( $content ) {
return $content;
}
/**
* Processes content from storage.
*
* @param string $content the content to be processed
* @return string the content after it has been processed
*/
protected function process_content_from_storage( $content ) {
return $content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment