I am using WooCommerce and I added the following code on content-single-product.php
template to show last update of product:
<p class="data-label">Updated</p>
<p class="info"> <?php echo get_the_modified_time( 'F j, Y' ); ?> </p>
On single product pages I have enable reviews tab and comment tab so customer can add comment on a product.
The problem is when user add new review or comment to product, the last update date for the
product is changed to the date of its comment.
I don't want to change the last update date of product when user add new comment on any product.
I am using WooCommerce and I added the following code on content-single-product.php
template to show last update of product:
<p class="data-label">Updated</p>
<p class="info"> <?php echo get_the_modified_time( 'F j, Y' ); ?> </p>
On single product pages I have enable reviews tab and comment tab so customer can add comment on a product.
The problem is when user add new review or comment to product, the last update date for the
product is changed to the date of its comment.
I don't want to change the last update date of product when user add new comment on any product.
WooCommerce seems to update the 'last modified' value of a product on every change. If you want to take a look at the source code, go to woocommerce\includes\data-stores\class-wc-product-data-store-cpt.php
and check the function update
.
This solution seems to work, however it could be improved to make sure it doesn't mess up with anything else. Basically checks if the request has info of a comment and filters the query that modifies the post date to skip it. I didn't find any earlier hook than the query
filter.
add_filter('query', function($query){
if(isset($_POST['comment']) && strpos($query, 'post_modified')){
return '';
}
return $query;
});