Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JeroenSormani/865f3a262d357f40b2920f99d4585d9c to your computer and use it in GitHub Desktop.
Save JeroenSormani/865f3a262d357f40b2920f99d4585d9c to your computer and use it in GitHub Desktop.
Create product tab for product change logs
<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Add a custom product tab.
*/
function ace_product_change_log_tab( $tabs ) {
$tabs['change-log'] = array(
'label' => __( 'Log', 'woocommerce' ),
'target' => 'change-log',
'class' => array(),
'priority' => 90,
);
return $tabs;
}
add_filter( 'woocommerce_product_data_tabs', 'ace_product_change_log_tab' );
/**
* Contents of the change log product tab.
*/
function ace_product_change_log_tab_content() {
global $post;
$product = wc_get_product( $post );
remove_filter( 'pre_get_comments', 'ace_hide_product_log_comments' );
$changes = get_comments( array( 'post_id' => $product->get_id(), 'type' => 'product_log' ) );
add_filter( 'pre_get_comments', 'ace_hide_product_log_comments' );
?><div id='change-log' class='panel woocommerce_options_panel hidden'>
<table class="widefat striped" style="margin: -1px; width: calc(100% + 2px);">
<tbody><?php
foreach ( $changes as $change ) :
?><tr>
<td>
<strong><a href="<?php echo esc_url( get_edit_user_link( $change->comment_author_id ) ); ?>"><?php echo wp_kses_post( $change->comment_author ); ?></a></strong><br/>
<small><?php echo get_comment_date( '', $change->comment_ID ); ?></small>
</td>
<td><?php echo wp_kses_post( $change->comment_content ); ?></td>
</tr><?php
endforeach;
?></tbody>
</table><?php
?></div><?php
}
add_filter( 'woocommerce_product_data_panels', 'ace_product_change_log_tab_content' ); // WC 2.6 and up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment