我在评论表单中使用自定义字段“你喜欢这本书吗?”和“是”和“否”值。我想发送2个不同的自动回复评论,如果用户选择“是”,那么响应是“谢谢你的善意认可,客户的满意永远是我们的目标。”如果“不”,那么自动回答是“我们将努力做得更好”。我将非常感谢您的任何帮助...
//And this is how I send an auto reply to a comment
add_action( 'comment_post', 'author_new_comment', 10, 3 );
function author_new_comment( $comment_ID, $comment_approved, $commentdata ){
$comment_parent = (int) $commentdata['comment_parent'];
// If a new comment is a reply to another comment, don't do anything
if ( $comment_parent !== 0 ) {
return;
}
//How do I add a response if the comment contains the value of the [likebook ] meta field???
if( !empty( $_POST['likebook'] ) {
return;
}
$commentdata = [
'comment_post_ID' => $commentdata['comment_post_ID'],
'comment_author' => 'admin',
'comment_author_email' => 'admin@example.com',
'comment_author_url' => 'http://example.com',
'comment_content' => 'Thank you for your kind recognition, customer satisfaction is always our goal.',
'comment_type' => 'comment',
'comment_parent' => $comment_ID,
'user_ID' => 1,
];
wp_new_comment( $commentdata );
}
1条答案
按热度按时间osh3o9ms1#
试试这些,