Skip to content

Instantly share code, notes, and snippets.

@mattheu
Last active August 29, 2015 14:23
Show Gist options
  • Save mattheu/380c841e611a64ab329b to your computer and use it in GitHub Desktop.
Save mattheu/380c841e611a64ab329b to your computer and use it in GitHub Desktop.
Close comments for new autodrafts
<?php
/**
* Set default comment status to closed for woocommerce products.
*/
add_filter( 'wp_insert_post_data', function( $data, $postarr ) {
// Auto draft is the status given to the initial post created
// when visiting the 'add new product' page in the WP-Admin.
// This still allows posts to be created programatically with comments open.
// This will default to the value of `default_comment_status`
if ( 'product' === $data['post_type'] && 'auto-draft' === $data['post_status'] ) {
$data['comment_status'] = 'closed';
$data['ping_status'] = 'closed';
}
return $data;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment