Apply function only on woocommerce (date update)

there is a way to apply this function only on woocommerce post type?

function reset_post_date_wpse_121565($data,$postarr) {
// var_dump($data,$postarr); die; // debug
$data['post_date'] = $data['post_modified'];
$data['post_date_gmt'] = $data['post_modified_gmt'];
return $data;
}
add_filter('wp_insert_post_data','reset_post_date_wpse_121565',99,2);

I need to reset only woocommerce product after update.

Related posts

1 comment

  1. for wp_insert_post_data filter, just compare the post type to the cpt.

    function reset_post_date_wpse_121565($data,$postarr) {
    
       if($data['post_type'] !== 'product')
            return $data;
    
       $data['post_date'] = $data['post_modified'];
       $data['post_date_gmt'] = $data['post_modified_gmt'];
       return $data;
    }
    add_filter('wp_insert_post_data','reset_post_date_wpse_121565',99,2);
    

Comments are closed.