03 July 2021

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'];

$country  = $vendor_data['address']['country'];

$state    = $vendor_data['address']['state'];

$store_email    = $vendor_data['store_email'];

$phone    = $vendor_data['phone'];

$store_location    = $vendor_data['store_location'];

How to get review bar in Woo-commerce in wordpress.

Get review bar in Woo-commerce in wordpress.


 function get_all_products() {

    $ps = new WP_Query( array(
        'post_type' => 'product',
        'post_status' => 'publish',
'author' => 130,
        'posts_per_page' => '-1'
    ) );
    $arr = array();
    while($ps->have_posts()){
      $ps->the_post();
      $arr[] = get_the_ID();
    }
    return $arr;
}



function get_store_bar_rating(){
  $products = get_all_products();
  foreach ($products as $key => $value) {
$product_id = $value;
$get_rating_count = get_post_meta( $product_id, '_wc_rating_count', true );
   if(is_array($get_rating_count)){
foreach($get_rating_count as $key=>$value){
if($key==1){
$onerating += $value;
}
if($key==2){
$tworating += $value;
}
if($key==3){
$threerating += $value;
}
if($key==4){
$fourrating += $value;
}
if($key==5){
$fiverating += $value;
}
}
   } 
  }


if(empty($onerating)){
$onerating = 0;
}
if(empty($tworating)){
$tworating = 0;
}
if(empty($threerating)){
$threerating = 0;
}
if(empty($fourrating)){
$fourrating = 0;
}
if(empty($fiverating)){
$fiverating = 0;
}

$totalrating = $onerating + $tworating + $threerating + $fourrating + $fiverating;

/*    echo '1 =' . $onerating;
   echo '<br>';
   echo '2 =' . $tworating;
   echo '<br>';
   echo '3 =' . $threerating;
   echo '<br>';
   echo '4 =' . $fourrating;
   echo '<br>';
   echo '5 =' . $fiverating;
   echo '<br>'; */
$onewidth   = $onerating * 100 / $totalrating;
$twowidth   = $tworating * 100 / $totalrating;
$threewidth = $threerating * 100 / $totalrating;
$fourwidth  = $fourrating * 100 / $totalrating;
$fivewidth  = $fiverating * 100 / $totalrating;
   
?>
<style>

.review_box_con{

}
.review_row{
  display : flex;
  margin-bottom:20px
}
.outer_review_bar{
  width:100%;
  height:30px;
  background:#f1f1f1;
  margin-left : 70px;
  overflow:hidden;
}
.inner_review_bar{
  height:30px;
  background:#F6C1B8;
}
.review_star_tx {
    font-size: 20px;
    font-weight: 500;
    display: inline-block;
    width: 87px;
    text-align: center;
    line-height: 28px;
}
span.total_bar_rating {
    font-size: 21px;
    font-weight: 700;
    margin-bottom: 9px;
    box-sizing: border-box;
    display: inline-block;
}
</style>
<div class="review_box_con">
<span class="total_bar_rating"><?php if(empty($totalrating)){ echo '0'; }else { echo $totalrating; } ?> reviews</span> 
    <div class="review_row">
      <span class="review_star_tx">5 Star</span>
    <div class="outer_review_bar">
      <div class="inner_review_bar" style="width:<?php if(!empty($fivewidth)){ echo $fivewidth .'%'; }else { echo '0'; } ?>">
      </div>      
    </div>
    <span class="review_star_tx" ><?php if(empty($fiverating)){ echo '0'; }else { echo $fiverating; } ?></span>
    </div>
      <div class="review_row">
      <span class="review_star_tx">4 Star</span>
    <div class="outer_review_bar">
       <div class="inner_review_bar"  style="width:<?php if(!empty($fourwidth)){ echo $fourwidth .'%'; }else { echo '0'; } ?>">
      </div>      
    </div>
    <span class="review_star_tx" ><?php if(empty($fourrating)){ echo '0'; }else { echo $fourrating; } ?></span>
    </div>
      <div class="review_row">
      <span class="review_star_tx">3 Star</span>
    <div class="outer_review_bar">
       <div class="inner_review_bar"  style="width:<?php if(!empty($threewidth)){ echo $threewidth .'%'; }else { echo '0'; } ?>">
      </div>      
    </div>
    <span class="review_star_tx" ><?php if(empty($threerating)){ echo '0'; }else { echo $threerating; } ?></span>
    </div>
      <div class="review_row">
      <span class="review_star_tx">2 Star</span>
    <div class="outer_review_bar">
       <div class="inner_review_bar"  style="width:<?php if(!empty($twowidth)){ echo $twowidth .'%'; }else { echo '0'; } ?>">
      </div>      
    </div>
    <span class="review_star_tx" ><?php if(empty($tworating)){ echo '0'; }else { echo $tworating; } ?></span>
    </div>
      <div class="review_row"> 
      <span class="review_star_tx">1 Star</span>
    <div class="outer_review_bar">
       <div class="inner_review_bar"  style="width:<?php if(!empty($onewidth)){ echo $onewidth .'%'; }else { echo '0'; } ?>">
      </div>      
    </div>
    <span class="review_star_tx" ><?php if(empty($onerating)){ echo '0'; }else { echo $onerating; } ?></span>
    </div>
  
</div>

<?php
 }
add_shortcode('store_bar_rating', 'get_store_bar_rating'); 
 
 

User it anywhere

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

21 June 2021

How to create floating animation in HTML/CSS?

 Create floating animation in HTML/CSS.


.floating_x {

animation-name: floating_x;

animation-duration: 6s;

animation-iteration-count: infinite;

animation-timing-function: ease-in-out;

}


@keyframes floating_x {

from {

transform: translate(0px, 0px)

}

65% {

transform: translate(15px, 0px)

}

to {

transform: translate(0px, 0px)

}

}


.floating_y {

animation-name: floating_y;

animation-duration: 4s;

animation-iteration-count: infinite;

animation-timing-function: ease-in-out;

}


@keyframes floating_y {

from {

transform: translate(0px, 0px)

}

65% {

transform: translate(0px, -20px)

}

to {

transform: translate(0px, 0px)

}

}


.floating_y2 {

animation-name: floating_y2;

animation-duration: 4s;

animation-iteration-count: infinite;

animation-timing-function: ease-in-out;

animation-delay: 1s

}


@keyframes floating_y2 {

from {

transform: translate(0px, 0px)

}

50% {

transform: translate(0px, -20px)

}

to {

transform: translate(0px, 0px)

}

}


.floating_y3 {

animation-name: floating_y3;

animation-duration: 5s;

animation-iteration-count: infinite;

animation-timing-function: ease-in-out

}


@keyframes floating_y3 {

from {

transform: translate(0px, 0px)

}

65% {

transform: translate(0px, -20px)

}

to {

transform: translate(0px, 0px)

}

}

18 June 2021

How to convert blob url into blob source code in jquery.

 Convert blob url into blob source code in jQuery


jQuery('.save_video_rec').click(function(){
        
        // blob url
        var videoblob = $('.j-video_result').attr('src');
        var blobUrl = videoblob;
        alert(blobUrl);
        var xhr = new XMLHttpRequest;
        xhr.responseType = 'blob';

        xhr.onl oad = function() {
        var recoveredBlob = xhr.response;

        var reader = new FileReader;

        reader.onl oad = function() {
         var blobAsDataUrl = reader.result;
        //  window.location = blobAsDataUrl;
        //    $('.audiovalue').val(blobAsDataUrl);
            alert(blobAsDataUrl);
        };

        reader.readAsDataURL(recoveredBlob);
        };

        xhr.open('GET', blobUrl);
        xhr.send();
        
    });

22 May 2021

How to redirect after checkout in woo-commerce in Wordpress.

Redirect after checkout in woo-commerce in Wordpress. 


Paste in function.php

/*

Redirect loggedin user to order details page

*/

if(is_user_logged_in())

{

add_action( 'template_redirect', 'woocommerce_redirect_after_checkout' );

}

function woocommerce_redirect_after_checkout() {

global $wp;

if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {

$redirect_url = home_url().'/my-account/view-order/'.$wp->query_vars['order-received'] ;


wp_redirect($redirect_url );


exit;

}

}


How to create custom guest popup for checkout with wordpress menu in wordpress.

Create custom guest popup for checkout with wordpress menu in wordpress.

Paste in function.php

function override_checkout_email_field( $fields ) {
global $wpdb;
  $popup_id = $_COOKIE['popup_id'];
global $wpdb;
$tablename = $wpdb->prefix . "guest_users";
$result = $wpdb->get_results ("SELECT * FROM $tablename WHERE id=$popup_id");
foreach ( $result as $print )   {

}
$survey_email = $print->email;
$survey_phone = $print->phone;
    global $woocommerce;
    //$survey_email = $woocommerce->session->get('survey_email');
    if(!is_null($survey_email)) {
      $fields['billing']['billing_email']['default'] = $survey_email;
    }
     if(!is_null($survey_phone)) {
      $fields['billing']['billing_phone']['default'] = $survey_phone;
    } 
    return $fields;
}

add_filter( 'woocommerce_checkout_fields' , 'override_checkout_email_field' );


// Show the popup to fetch email and phone number and store in the database




function guest_popup(){
$popup_id = $_COOKIE['popup_id'];
if(isset($_POST['guest_popup_bt'])){
$email = $_POST['email'];
$phone = $_POST['phone'];
date_default_timezone_set('Asia/Kolkata');
$date = date('d-m-Y h:i:s a');
global $wpdb;
$table_name = $wpdb->prefix . "guest_users";
$wpdb->insert($table_name, array('email' => $email, 'phone' => $phone, 'created_at' => $date) ); 
$lastid = $wpdb->insert_id;
if(!empty($lastid)){
//setcookie('popup_id', $lastid, strtotime('+1 day'), COOKIEPATH, COOKIE_DOMAIN);
setcookie('popup_id', $lastid, strtotime("+1 year"), COOKIEPATH, COOKIE_DOMAIN);
if ( ! WC()->cart->get_cart_contents_count() == 0 ) { 
wp_redirect(site_url().'/checkout');
}else{
wp_redirect(site_url().'/shop');
}
}
}
?>
<?php
if(!is_user_logged_in() && is_cart() && empty($popup_id)){
?>
<style>
.popup-container {
    width: 100%;
    height: 100vh;
    background-color: #000000bf;
    position: fixed;
    display: flex;
    justify-content: Center;
    align-items: center;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 9999999;
    left: 0;
}

.popup-box input[type="email"],input[type="number"] {
    width: 100%;
    font-size: 15px;
    padding: 7px 7px;
}
input.guest_popup_bt {
    padding: 5px 16px;
    background: #000;
    border: #000;
    color: white;
    font-weight: 400;
    font-size: 16px;
}
.form-filed-box {
    margin-top: 10px;
}
.popup-box h4 {
    margin: 0;
    font-size: 17px;
    text-align: center;
    font-weight: 400;
    letter-spacing: 1px;
    margin-bottom: 12px;
}
.popup-box {
    padding: 59px 37px;
    background: white;
    border-radius: 9px;
    width: 386px;
position:relative;
}

.popup_close_bt {
    background: #000;
    color: White;
    position: absolute;
    right: -15px;
    top: -15px;
    border-radius: 200%;
    width: 30px;
    height: 30px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
cursor:pointer;
}
</style>
<script>
jQuery(document).ready(function($){
$('.popup_close_bt').click(function(){
$('.popup-container').css('display','none');
});

if (typeof $.cookie('popup_id') === 'undefined'){

$('.checkout-button').click(function(e){
e.preventDefault;
jQuery('.popup-container').css('display','flex');
return false;
});
}
});
</script>
<div class="popup-container">
<div class="popup-box">
<div class="popup_close_bt">X</div>
<form action="" method="post">
<h4>Please enter the following detail to move forward</h4>
<div class="form-filed-box">
<label>Email</label>
<input type="email" name="email" >
</div>
<div class="form-filed-box">
<label>Phone no.</label>
<input type="text" name="phone" >
</div>
<div class="form-filed-box">
<input type="submit" name="guest_popup_bt" class="guest_popup_bt" value="Submit">
</div>
</form>
</div>
</div>
<?php
}
}
add_action('wp_head','guest_popup');


add_action("admin_menu", "addMenu");

function addMenu() {
    add_menu_page("Guest Info", "Guest Info", "edit_posts",
        "guest-popup", "displayPage", null,10);
}

add_filter("custom_menu_order", "allowMenuStructure");
add_filter("menu_order", "loadMenuStructure");

function displayPage() {
?>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.min.css">



<script src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>  



<script>

$(document).ready(function() {
    $('#example').DataTable( {
      /*   dom: 'Bfrtip',
        buttons: [
            'copy', 'excelFlash', 'excel', 'pdf', 'print',{
            text: 'Reload',
            action: function ( e, dt, node, config ) {
                dt.ajax.reload();
            }
        }
        ] */
    } );
} );

</script>


<table id="example" class="display nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>S.r</th>
                <th>Date</th>
                <th>Email</th>
                <th>Phone</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>S.r</th>
                <th>Date</th>
                <th>Email</th>
                <th>Phone</th>
            </tr>
        </tfoot>
        <tbody>
<?php
global $wpdb;
$tablename = $wpdb->prefix . "guest_users";
$result = $wpdb->get_results ("SELECT * FROM $tablename order by Id DESC");
//print_r($result);
$i = 1 ;
foreach ( $result as $print )   {
?>
            <tr>
                <td><?php echo $i; ?></td>
                <td><?php echo $print->created_at; ?></td>
                <td><a href="mailto:<?php echo $print->email; ?>"><?php echo $print->email; ?></a></td>
                <td><a href="tel:<?php echo $print->phone; ?>"><?php echo $print->phone; ?></a></td>

            </tr>
<?php
$i++;
}
?>
        </tbody>
    </table>
<?php
}

12 May 2021

PHP file upload - Dynamically Add Remove input fields using JQuery and PHP.

PHP file upload - Dynamically Add Remove input fields using JQuery and PHP.




Paste in View


<style>
.file {
  visibility: hidden;
  position: absolute;
}

.btn.btn-primary {
  background-color: #007bff;
  border-color: #007bff;
  outline: none;
  color: #fff;
}

.multi-cus-filed{
  position:relative;
}

.remove-cus-filed {
background: #007bff;
border-radius: 200%;
padding: 4px 13px;
border: none;
color: white;
font-size: 19px;
position: absolute;
top: 32px;
right: -40px;
}


.multi-cus-filed{
  position:relative;
}

.remove-cus-filed {
background: #007bff;
border-radius: 200%;
padding: 4px 13px;
border: none;
color: white;
font-size: 19px;
position: absolute;
top: 32px;
right: -40px;
}
</style>
  
  
  
<form role="form" action="" method="POST" enctype="multipart/form-data">
<div class="multi-field-wrapper">
  <div class="multi-fields">
<div class="multi-field multi-cus-filed">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="ReportName">Name</label>
<div>
  <input type="text" class="form-control "  name="title[]" placeholder="Enter Report name" >
</div>
</div>
</div>
<div class="col-sm-6">
  <div class="form-group">
<label for="ReportFile">File</label>
<input type="file" name="report[]" class="file">
<div class="input-group mb-3">
  <div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="fas fa-paperclip"></i></span>
  </div>
  <input type="text" class="form-control" disabled placeholder="Upload File" aria-label="Upload File" aria-describedby="basic-addon1">
  <div class="input-group-append">
<label class="browse input-group-text btn btn-primary" id="basic-addon2"><i class="fas fa-search"></i>  Choose</label>
  </div>
</div>
  </div>
</div>
</div>
  <button type="button" class="remove-field remove-cus-filed">X</button>
</div>
  </div>
<button type="button" class="add-field btn btn-primary">Add field</button>
<button type="submit" name="uploadreport" value="uploadreport" class="btn  btn-outline-primary">Submit</button>
  </div>
  
</form>


<script>

$('.multi-field-wrapper').each(function() {
    var $wrapper = $('.multi-fields', this);
    $(".add-field", $(this)).click(function(e) {
        $('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus();
    });
    $('.multi-field .remove-field', $wrapper).click(function() {
        if ($('.multi-field', $wrapper).length > 1)
            $(this).parent('.multi-field').remove();
    });
});


$(document).on("click", ".browse", function() {
  var file = $(this)
    .parent()
    .parent()
    .parent()
    .find(".file");
  file.trigger("click");
});
$(document).on("change", ".file", function() {
  $(this)
    .parent()
    .find(".form-control")
    .val(
      $(this)
        .val()
        .replace(/C:\\fakepath\\/i, "")
    );
});



</script>
<script>
$(function () {
  bsCustomFileInput.init();
});
</script>


Paste in Controller


<?php


$user_id = $this->session->userdata('user_id');
$doc_patients = $this->User_Model->get_single_appointments($appointment_id);
$Patient_id = $doc_patients[0]->uid;
//$json_arr = json_decode($Patient_his_titles, true);
//print_r($json_arr);
// die();
if($this->input->post('uploadreport')=='uploadreport' || $this->input->post('uploadprescription')=='uploadprescription' ){

$report_type = 'testreport';
$title = $this->input->post('title');
$files = $_FILES['report']['name'];
$total_reports = count($files);
  $file = array();
  $upload_name = array();
  $report_title = array();
for($i=0; $i<$total_reports; $i++){
//echo $i.'jassi <br>';
$report_name = $title[$i];
$file_name = $_FILES['report']['name'][$i];
if(!empty($file_name) || !empty($report_name)){
$_FILES['file']['name'] = $_FILES['report']['name'][$i];
$_FILES['file']['type'] = $_FILES['report']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['report']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['report']['error'][$i];
$_FILES['file']['size'] = $_FILES['report']['size'][$i];
  
$config['upload_path']          = 'assets/new-template/patient-reports';
//$config['allowed_types']        = '*';
$config['allowed_types']        = 'docx|doc|DOC|DOCX|rtf|pdf|gif|jpg|png|jpeg';
//$config['max_width']            = 128;
//$config['max_height']           = 128;
$config['encrypt_name']         = TRUE;
$this->load->library('upload', $config);


if ( ! $this->upload->do_upload('file'))
{
$error = $this->upload->display_errors();

} 
else
{ 

$data = array('upload_data' => $this->upload->data());
$upload_name[] = $this->upload->data('file_name');
$report_title[] = $report_name;
}  

}
}
 
$title = $report_title;
$files = $upload_name;
if($total_reports==$i){
 
$patient_history = $this->User_Model->patient_reports($appointment_id,$user_id,$report_type);

if(count($patient_history)>0){
$Patient_his_id = $patient_history[0]->id;
$Patient_his_titles = $patient_history[0]->title;
$Patient_his_reports = $patient_history[0]->doc;
$oldtitle = json_decode($Patient_his_titles,true);
$oldreport = json_decode($Patient_his_reports,true);
$titleresult = array_merge($title, $oldtitle);
$filesresult = array_merge($files, $oldreport);
$newtitle = json_encode($titleresult);
$newreport = json_encode($filesresult);

$data = array(
'title' => $newtitle,
'doc' => $newreport
);

$update = $this->User_Model->update_patient_report($data,$Patient_his_id);
}
else{
$titles = json_encode($title);
$reports = json_encode($files);
$data = array(
'appointment_id' => $appointment_id,
'doc_id' => $user_id,
'Patient_id' => $Patient_id,
'title' => $titles,
'doc' => $reports,
'type' => $report_type,
'status' => 1
);
$update = $this->User_Model->insert_patient_report($data);
}
if($this->db->affected_rows()){
$this->session->set_flashdata('success', 'The report has been updated successfully.');
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
} 
//die();
}
?>


In Model

Create function according to you.

How to fetch instagram posts data?

Fetch Instagram posts data by pasting this code in browser console. (() => { /* ====================================================...