• Resolved mattjdever

    (@mattjdever)


    I am working on a convertor that takes your exported csv and parses it into a format required by a Quickbooks Importer tool.

    Right now, I click export from your plugin, and then I run my php convertor on your outputted csv file, and it creates the properly formatted csv file.

    Which hook would I use if I wanted to put my code inside of a WordPress plugin.
    basically I would like to hook in right after the exporter builds the file, and pass the file handle, so i could run my parse code, and then save the newly parsed file.

    I’m hoping that this file could then by emailed weekly.

    I’m thinking that hooking into woe_formatter_csv_finished or woe_custom_export_to_email is what i’m looking for. I’m just scratching my head at what gets called with it.

    Thanks.

    • This topic was modified 6 years, 9 months ago by mattjdever.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author algol.plus

    (@algolplus)

    try use hook

    add_action( "woe_csv_print_footer", function($handle, $formatter) {
    
    }, 10, 2);

    it will be run from line
    do_action( "woe_{$this->format}_print_footer", $this->handle, $this );

    Thread Starter mattjdever

    (@mattjdever)

    Clarifying that $handle is the csv datastream? What is $formatter?

    Thanks,

    Plugin Author algol.plus

    (@algolplus)

    Clarifying that $handle is the csv datastream?
    – Yes, you can rewind($handle) and read it from begin.

    What is $formatter?
    – it’s object of class WOE_Formatter_Csv.

    Plugin Author algol.plus

    (@algolplus)

    hi Matt

    If you still need my help , submit your unfinished code to helpdesk.

    I’ll add new hook if it’s necessary.

    thanks, Alex

    Thread Starter mattjdever

    (@mattjdever)

    OK. I just posted a request… It comes down to one thing i think…
    I’m just not sure how to read $handle.. my code doesnt show anything in $handle…

    Quick code synopsis here:
    add_action( “woe_csv_print_footer”, function($handle, $formatter) {

    $fh = stream_get_contents($handle, -1, 0);
    $csv = new parseCSV($fh);
    write_log($csv);
    $newhandle = “parsed-export.csv”;
    $data = $csv->data;
    … do stuff here …

    //save csv as new csv file
    echo “Saving New Web Parsed-Orders: $newhandle\n”;
    $handle = $newhandle;
    fputcsv($handle,$newcsv->data);
    }, 10, 2);

    Thanks for all your help. We absolutely love your plugin. and i will definetly use it with other clients.

    Plugin Author algol.plus

    (@algolplus)

    please, adapt this code

    add_action( "woe_formatter_finish", function($formatter) {
     $exported_contents = file_get_contents($formatter->filename); // Or use fopen+fgetcsv+fclose  for reading
      // generate new contents
      file_put_contents($formatter->filename,$new_contents);  // Or use fopen+fputcsv+fclose  
    } );

    $formatter->filename was added in version 1.5.3

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘add hook to run custom code on csv after export’ is closed to new replies.