Adding Category to export

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #40350
    onkelfu
    Participant

      Hi,

      I’m trying to edit the CSV-Export. I need to export an additional column which contains the category and parent category of each item. Tried editing the subpage.reports.php but I don’t seem to find the correct query, that’s why I’m asking for your support.

      Thanks in advance!

      Best regards!

      #40352
      Olly
      Admin & Mod

        may i suggest this resource
        https://docs.wp-pizza.com/developers/?section=create-your-own-sales-report

        as all that data – and more -exists already
        (see especially the wppizza_filter_report_datasets and wppizza_filter_reports_export_results filter hooks)

        PS: it seems to me you are also editing core files – that is never good idea

        #40425
        onkelfu
        Participant

          Thanks for your help, but I can’t get it working.

          I’m trying to create a list of all orders, ordered by category. Doesn’t matter if it’s a CSV Export or a table on a single page. Maybe there is an easier way to achieve this? Could you please give me another hint?

          Thanks in advance!

          #40426
          Olly
          Admin & Mod

            perhaps the following would be simpler in this case
            https://docs.wp-pizza.com/developers/?section=function-wppizza_get_orders

            i.e something along these lines

            
            $args = array(
            'query'=>array(
            'payment_status' => 'COMPLETED',//get completed orders only 
            ),
            );
            $orders = wppizza_get_orders($args);
            /* 
            items for each order 
            */
            foreach($orders['orders']['items'] as $item){
            //$item['cat_id_selected'] => [int] category id the item was in when it was added to cart (as an item can belong to multiple categories)
            //$item['item_in_categories'] => [array] all categories an item belongs to (where key -> cat id)
            /*
            do some grouping by catid i would think here , or whatever it is you need to do 
            */	
            }
            
            #40465
            Olly
            Admin & Mod

              correction:
              the foreach loop above should be nested – i.e something like

              
              $args = array(
              'query'=>array(
              'payment_status' => 'COMPLETED',//get completed orders only 
              ),
              );
              $data = wppizza_get_orders($args);
              foreach($data['orders'] as $order){				
              foreach($order['order']['items'] as $item){
              //$item['cat_id_selected'] => [int]...
              //$item['item_in_categories'] => [array] ...
              }
              }
              

              to loop through each item of each order

              sorry about that

              #40469
              onkelfu
              Participant

                Hi Olly

                thanks for that details and the correction. At the moment, I don‘t know how to implement that for getting output on a single page. Can you help me to get started?

                Best regards!

                #40471
                Olly
                Admin & Mod

                  you mean you don’t know how to echo/print (i.e output) things in php ?

                  #40472
                  onkelfu
                  Participant

                    😉
                    No, it’s not that bad! I do know how to echo / print etc. things in php. I just don’t know, where to put that code. Should I create a new php file or should I modify an existing one. Putting the code on a new wordpress-site or post will not work, I think.

                    Sorry for the confusion and thank you!

                    #40484
                    Olly
                    Admin & Mod

                      you need to familiarise yourself with wordpress action and filters and generally really how it does things (see the wp codex)
                      perhaps something like this in your themes functions php (just as an example, there are a million ways of doing this)

                      
                      add_action('wp', 'my_export_function_name');
                      function my_export_function_name(){
                      global $post;
                      if($post->ID == [some post/page id]){
                      /*
                      run the query and print the output or some script that automatically creates and downloads the csv
                      or whatever else it is you need to do 
                      */	
                      }
                      }
                      

                      but please note: this is about the basics of wordpress, i cannot really offer support for this sort of thing in general

                      some basic action/filter overview can also be found here: https://docs.wp-pizza.com/developers/?section=filters-actions-functions

                    Viewing 9 posts - 1 through 9 (of 9 total)
                    • The topic ‘Adding Category to export’ is closed to new replies.