Posted product reviews in Woo commerce cannot be viewed from the admin to either approve or disapprove

I hereby attach my code snippets:-

// comments handler in functions.php
add_action(‘comment_post’,’my_comment_handler’,20, 2);
function my_comment_handler($comment_ID,$comment_status){
if(!empty($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’){
switch($comment_status){
case “0”:
wp_notify_moderator($comment_ID);
case “1”: //Valid comment
echo “success”;
$commentdata = get_comment($comment_ID, ARRAY_A);
$post = get_post($commentdata[‘comment_post_ID’]);
wp_notify_postauthor($comment_ID, $commentdata[‘comment_type’]);
break;
default:
echo “error”;
}
exit;
}

}

javascript that’s enqueued

jQuery(document).ready( function($) {
var commentform = $(‘#commentform’);

/* var comment = $(‘#comment’);
var rating = $(‘#rating’); */
commentform.prepend(‘<div class=”review-status”></div>’);
/* $(‘.stars’).click(function(){
// alert (“you clicked stars”);
if($(‘#mystyle’)){
$(‘#mystyle’).remove();
}
}); */

var statusdiv =$(‘.review-status’);
$(commentform).submit(function(e){
e.preventDefault();

var formdata=commentform.serialize();

validate([$(‘#comment’),$(‘#rating’),$(‘#author’),$(‘#email’),$(‘#wpgdprc’)]);//does basic validation to check for empty values

//alert(formdata);
//Add a status message
statusdiv.html(‘<p>Processing…</p>’);
//Extract action URL from commentform
var formurl=commentform.attr(‘action’);
$.ajax({
type: ‘post’,
url: formurl,
data: formdata,
error: function(XMLHttpRequest, textStatus, errorThrown){
statusdiv.html(‘<p class=”wdpajax-error” >You might have left one of the fields blank, or be posting too quickly</p>’);

},
success: function(data, textStatus){
/* if(data==”success”)
statusdiv.html(‘<p class=”ajax-success” >Thanks for your Review.It will be published,once it’s approved</p>’);
else */
statusdiv.html(‘<p class=”ajax-error” >Thanks for your Review.It will be published,once it’s approved</p>’);
commentform.find(‘textarea[name=comment]’).val(”);
$(‘.comment-notes’).html(”);

$(‘:input’,’#commentform’).not(‘:button, :submit, :reset, :hidden’).val(”).prop(‘checked’, false) .prop(‘selected’, false);//resetting form fields
//$(‘.stars.selected ‘).css({‘background-color’:’green’});

// $(‘head’).append(‘<style id=”mystyle” type=”text/css”> p.stars.selected a.active:before,p.stars.selected a:not(.active):before{opacity: 0.2;} </style>’);

},
});
return false;

});
function validate(x){
var valid = true;
var statusmsg=”;
$.each(x,function(index,inputId){
if(!inputId.is(“:checkbox”)) {

if(inputId.val()==”){
valid =false;
var name = inputId.attr(‘name’);
statusmsg+= ‘<p>Fill the ‘+name+'</p><br/>’;
}

}
else{
if(!inputId.prop(‘checked’)){
valid =false;
statusmsg+= ‘<p>Click the checkbox </p><br/>’;

}

}

});
if(valid==false){
statusdiv.html(statusmsg);
$(‘#email-notes’).html(”);
exit;
}

}

});

Read more here:: Posted product reviews in Woo commerce cannot be viewed from the admin to either approve or disapprove

Leave a Reply

Your email address will not be published. Required fields are marked *