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;
- $data = array();
- $data[] = 'Code';
- $data[] = 'Description';
- $fh = @fopen( $filename, '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);
- $currpage = site_url() .'/wp-admin/tools.php?page=export';
- wp_redirect($currpage);
- // Make sure nothing else is sent, our file is done
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement