Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create the Catalogue Code File
- function sp_create_catalogues() {
- $terms = get_terms( 'product_cat',
- array(
- 'parent' => 0,
- 'hide_empty' => 1
- )
- );
- $count = count($terms);
- if ($count == 0) return;
- $file_options = get_option('sp_file');
- $shortname = isset( $file_options['catalogues'] ) && !is_null( $file_options['catalogues'] ) ? $file_options['catalogues'] : 'Catalogues.csv';
- $filename = SP_FILE_PATH .$shortname;
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header('Content-Description: File Transfer');
- header('Content-type: application/octet-stream');
- header('"filename=' .$filename .'"');
- header("Expires: 0");
- header("Pragma: public");
- $data = array();
- $data[] = 'Code';
- $data[] = 'Description';
- $fh = @fopen( 'php://output', 'w' );
- fputcsv($fh, $data);
- foreach ( $terms as $term ) {
- // Put the data into the stream
- $data = array();
- $data[] = $term->slug;
- $data[] = html_entity_decode($term->name);
- fputcsv($fh, $data);
- $children = get_terms( 'product_cat',
- array(
- 'parent' => $term->term_id,
- 'hide_empty' => 1
- )
- );
- $count = count($children);
- if ($count > 0) {
- foreach ( $children as $child ) {
- $data = array();
- $data[] = $child->slug;
- $data[] = '- ' .html_entity_decode($child->name);
- fputcsv($fh, $data);
- }
- }
- }
- // Close the file
- fclose($fh);
- // Make sure nothing else is sent, our file is done
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement