• Resolved pjkozlowskijr

    (@pjkozlowskijr)


    Hello,

    When activity is related to a post, is it possible to log the post ID and include it as its own column in history exports and/or on the dashboard log page?

    For example, I had to make updates to multiple WooCommerce orders, of which the order numbers needed to be shared with colleagues. I made the mistake of not tracking order numbers as the changes were made (silly I know, but onward and upward). The challenge is that orders are now mixed in with a bunch of others with the same order status across a date range of 1 month. I can find the updates I performed using the following filters:

    • Custom date range of the day work was performed
    • Containing words “updated order”
    • Message type = “Posts updated”
    • My user account

    However, in both the dashboard view and log export, the post ID (which is the order number) is not included, only the post title and date/time.

    Ideally I’d like the log entry to say something like “Order 12345 – September 13, 2023 @ 10:45am” so my colleagues can see the order number without having to click into each order or cross-reference order dates/times.

    I know making changes to logging won’t allow me to go back and capture order details referenced above. I’m asking this question for future use in case something similar happens.

    Is this possible? Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author eskapism

    (@eskapism)

    I tried to modify the output but was unable to do so in the current version of the plugin. But for the next version this will be possible thanks to a new filter simple_history/get_log_row_plain_text_output/output. Using this filter you will be able to modify the output the always include the post id.

    So wait until next version of Simple History is released, it is probably version 4.6.0 and I will try to release it shortly.

    add_filter(
        'simple_history/get_log_row_plain_text_output/output',
        'modify_plain_text_output_to_include_post_id',
        10,
        3
    );
    
    function modify_plain_text_output_to_include_post_id( $output, $row, $logger ) {
        // Bail if not from correct logger.
        if ( 'SimplePostLogger' !== $logger->get_slug()) {
            return $output;
        }
    
        $context = $row->context;
    
        // Bail if not correct post type.
        if ( ! in_array( $context['post_type'], ['post', 'wc_orders'] ) ) {
            return $output;
        }
    
        return $output . ' (Post ID: ' . esc_html( $context['post_id'] ) . ')';
    }
    
    Thread Starter pjkozlowskijr

    (@pjkozlowskijr)

    Awesome. Thanks for the quick reply. I will keep an eye out for the next version and use the filter provided. Appreciate your help and all the work you do on this plugin!

    Plugin Author eskapism

    (@eskapism)

    @pjkozlowskijr the just released version 4.6.0 have the filter used above, so you can try the code now.

    Thread Starter pjkozlowskijr

    (@pjkozlowskijr)

    Apologies for the delay. Finally had a chance to test out this filter, and it works great! Thanks for this!

    I did modify the array checking post_types to isolate only WooCommerce shop orders (which is our main need). I changed the array FROM ['posts', 'wc_orders'] TO ['shop_order', 'shop_subscription', 'shop_order_refund'].

    Providing my modification here in case it’s useful to others:

    add_filter(
        'simple_history/get_log_row_plain_text_output/output',
        'modify_output_to_include_wc_order_number',
        10,
        3
    );
    
    function modify_output_to_include_wc_order_number( $output, $row, $logger ) {
        if ( 'SimplePostLogger' !== $logger->get_slug()) {
            return $output;
        }
    
        $context = $row->context;
    
        // Change the array that is 2nd argument to isolate different post types
        if ( ! in_array( $context['post_type'], ['shop_order', 'shop_subscription', 'shop_order_refund'] ) ) {
            return $output;
        }
    
        return $output . ' (Order #: ' . esc_html( $context['post_id'] ) . ')';
    }

    Example output of above code:

    • This reply was modified 1 year, 1 month ago by pjkozlowskijr. Reason: Reformat code for cleaner look
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is it possible to log post ID’ is closed to new replies.