Skip to main content

How to create custom product review section in woocommerce in WCFM?

Create custom  product review section in woocommerce in WCFM?





Paste in function.php

function fetch_vendor_product_reviews(){


// print_R($_POST);

$post_order_num = $_POST['post_order'];

$user_id = $_POST['store_id'];

$page = $_POST['page_num'];

if(empty($page)){

$page = 1;

}

if(empty($post_order_num) || $post_order_num == 1){

$post_order = 'DESC';

}

else{

$post_order = 'ASC';

}


if(!empty($user_id)){


$countreviews = get_comments(array(

'post_author'      => $user_id, 

        'status'   => 'approve',

        'post_status' => 'publish',

        'post_type'   => 'product',

        'count' => true

    ));

if($countreviews>0){

  ?>

<!-- filter section start -->

<section class="filter-home-product">

<div class="container">

<div class="row">

<div class="col-lg-3 col-md-3 col-sm-12">

<div class="write-review pull-left">

<span><?php echo $countreviews; ?> Reviews</span>

</div>

</div>

<div class="col-lg-9 col-md-9 col-sm-12">

<div class="write-review pull-left">

<span>Write a Review</span>

</div>

<div class="write-review pull-right">

<ul>

<li>

<div> 

<span>Sort By: </span>

<select name="price" class="post_order" id="price">

<option value="1" <?php if($post_order_num ==1){ echo 'selected'; } ?> >Newest</option>

<option value="2" <?php if($post_order_num ==2){ echo 'selected'; } ?>>Oldest</option>

</select> 

</div>

</li>

</ul>

</div>

</div>

</div>

<?php


$limit = 2;

$offset = ($page * $limit) - $limit;

$pages = ceil($countreviews/2);


$comment_args = array( 

                'post_author'      => $user_id, 

                'status'      => 'approve', 

                'post_status' => 'publish', 

                'post_type'   => 'product',

                'offset'   => $offset,

                'number'   => $limit,

'orderby'=> 'ID', 

'order'   => $post_order

        );

$comments = get_comments($comment_args);

//print_R($comments);

if ( ! $comments ) return '';

/* echo '<pre>';

print_R($comments); */

foreach ( $comments as $comment ) {  

//echo $comment->comment_author; 

$comment_post_ID =  $comment->comment_post_ID; 

$comment_user_id = $comment->user_id; 

$product = wc_get_product( $comment_post_ID );

// if($comment_user_id==$user_id){

// if(get_comment_author($comment->comment_post_ID)==$user_id){

$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );

?>

<div class="row" style="margin-top:50px;">

<div class="col-lg-3 col-md-3 col-sm-12">

<div class="filter-product">

<div class="filter-author">

<i class="fa fa-user-circle"></i>

<h4><?php echo $comment->comment_author; ?></h4>

</div>

<div class="product-pics">

<?php  echo get_the_post_thumbnail($comment_post_ID); ?>

</div>

<div class="product-disc">

<h3><a href="<?php echo get_permalink( $comment_post_ID ); ?>"><?php echo $comment->post_title; ?></a></h3>

<p><?php echo get_woocommerce_currency_symbol() .''. $product->get_price(); ?></p>

</div>

</div>

</div>

<div class="col-lg-9 col-md-9 col-sm-12">

<div class="filter-product">

<div class="review-star text-center" style="text-align:left !important;">

<?php echo wc_get_rating_html( $rating ); ?>

<h3 style="font-weight:700;margin:20px 0 30px;">amazing!!</h3>

<p><?php echo $comment->comment_content; ?></p>

<div class="filter-product-btn">

<div class="write-review pull-left">

<p><i style="color:#387b50;" class="fa fa-check"></i>Recommends this project</p>

</div>

<div class="write-review pull-right">

<span>Did you find this helpful?</span>

<span class="up-down"><i class="fas fa-caret-up"></i>10</span>

<span class="up-down"><i class="fa fa-caret-down"></i>3</span>

</div>

</div>

</div>

</div>

</div>

</div>

<?php

}

?>

<div class="row">

<div class="col-lg-12 col-md-12 col-sm-12">

<div class="pagination-block">

<?php if($page != 1){

?>

<a class="next page-numbers" data-page="<?php echo $pages-1; ?>" href=""><i class="fas fa-angle-left" aria-hidden="true"></i></a>

<?php 

}

?>

<?php

if($pages != 1){

for($i=1; $i <= $pages; $i++)

{

?>

<span class="page-numbers <?php if($page==$i){ echo 'current'; } ?>" data-page="<?php echo $i; ?>" ><?php echo $i; ?></span>

<?php

}

}

?>

<?php if($page != $pages){

?>

<a class="next page-numbers" data-page="<?php echo $pages; ?>" href=""><i class="fas fa-angle-right" aria-hidden="true"></i></a>

<?php

}

?>

                       </div>

</div>

</div>

</div>

</section>


<?php

 }

 }


die();

}

add_action('wp_ajax_fetch_vendor_product_reviews','fetch_vendor_product_reviews');

add_action('wp_ajax_nopriv_fetch_vendor_product_reviews','fetch_vendor_product_reviews');






function vendor_product_reviews(){

global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post;

$store_id = '';

if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); }

if (  wcfm_is_store_page() ) {

$wcfm_store_url = get_option( 'wcfm_store_url', 'store' );

$store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) );

$store_id  = 0;

if ( !empty( $store_name ) ) {

$store_user = get_user_by( 'slug', $store_name );

}

$store_id  = $store_user->ID;

}

?>

<!-- Bootstrap CSS -->


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">

    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/custom-css/bootstrap.min.css">

<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/custom-css/bootstyle.css">

<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">

<div class="review_section_outer_box">

<div class="review_preloader">

<img src="<?php echo get_template_directory_uri(); ?>/assets/images/reivewloader.gif">

</div>

<div class="custom_review_box">

</div>

</div>


<script>

jQuery(document).ready(function($){

fetch_vendor_product_reviews(); 

$('body').on('change','.post_order',function(e){

e.preventDefault();

//$('.post_order').change(function(){

fetch_vendor_product_reviews(); 

});



$('body').on('click','.page-numbers',function(e){

e.preventDefault();

//$('.post_order').change(function(){

var page_num = $(this).data('page');

//alert(page_num);

fetch_vendor_product_reviews(page_num); 

});

 function fetch_vendor_product_reviews(page_num){

    var post_order = $('.post_order').val();

    var store_id = "<?php echo $store_id; ?>";

$('.review_preloader').css('display','flex')

var ajax =  "<?php echo admin_url('admin-ajax.php'); ?>";

    var data = {

'action' : "fetch_vendor_product_reviews",

'post_order' : post_order,

'store_id' : store_id,

'page_num' : page_num

    } 

    $.post(ajax,data,function(response){

//$("#response").html(response);

//console.log(response);

$('.custom_review_box').html(response);

$('.review_preloader').css('display','none')

    });

   }

    

});

</script>

<?php

 }

//add_action('wp_head','vendor_product_reviews');

add_shortcode('get_vendor_product_reviews', 'vendor_product_reviews'); 


Paste anywhere

<?php echo do_shortcode('[staff_detail]'); ?>



Comments

Popular posts from this blog

How to use inner html value or data in php from javascript(innerHTML)?

 use inner html value or data in php from javascript(innerHTML)? <html> <body> <p id="demo">use inner html value in php(innerhtml)</p> <script>   var jassi = document.getElementById("demo").innerHTML;   //document.write(jassi); </script> <?php $jassi = '<script>document.write(jassi);</script>'; echo $jassi; ?> </body> </html>

How to get store data from WCFM(Best Multi Vendor Marketplace) Plugin?

 Get store data from WCFM(Best Multi Vendor Marketplace) Plugin. global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post; $store_id = ''; if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); } if (  wcfm_is_store_page() ) { $wcfm_store_url = get_option( 'wcfm_store_url', 'store' ); $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) ); $store_id  = 0; if ( !empty( $store_name ) ) { $store_user = get_user_by( 'slug', $store_name ); } $store_id    = $store_user->ID; } $user_id = $store_id;  $vendor_data = get_user_meta( $user_id, 'wcfmmp_profile_settings', true ); $street_1 = $vendor_data['address']['street_1']; $street_2 = $vendor_data['address']['street_2']; $city     = $vendor_data['address']['city']; $zip      = $vendor_data['address']['zip&#

How to create login with phone number in woocommerce wordpress?

Create login with phone number in woocommerce wordpress. function wooc_extra_register_fields() {?>        <p class="form-row form-row-wide">        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>        <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />        </p>            <?php  }  add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );  function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) { if ( isset( $_POST['billing_phone'] ) ) {    $hasPhoneNumber= get_users('meta_value='.$_POST['billing_phone']);    if ( !empty($hasPhoneNumber)) {      $validation_er