Hi Anh..Thanks for your reply.
I cant make it work with your snippet..
But i found another way with another sniippet...Thank you very much for your help.
Here it is working snippet:
/**
* Enable or disable comments based on custom field Allow Comments.
*
* @param bool $open Whether comments should be open.
* @param int $post_id Post ID.
* @return bool Whether comments should be open.
*/
function wpdocs_comments_open( $open, $post_id ) {
$post = get_post( $post_id );
if (get_post_meta($post->ID, 'allow_comments', true)) {
$open = true;
}
return $open;
}
add_filter( 'comments_open', 'wpdocs_comments_open', 10, 2 );