Skip to main content

Posts

Showing posts from 2021

How to create flash message in Wordpress in PHP with session?

Create flash message in Wordpress in PHP. <?php  if(isset($_POST['submit'])){           session_start(); $info = '<div class="success">Application has been updated successfully.</div>'; $_SESSION['flashmessage'] = $info; exit(); } session_start(); if(!empty($_SESSION['flashmessage'])){  //echo 'jassi'; echo $_SESSION['flashmessage'];  unset( $_SESSION['flashmessage'] ); /* session_unset(); session_destroy(); */ } ?>

How to create quiz timer (Left time) in PHP?

Create quiz timer in PHP.   <!DOCTYPE html> <html lang="en"> <body> <center> <div class="time" id="navbar">Time left :<span id="timer"></span></div> <button class="button" id="mybut" onclick="myFunction()">START QUIZ</button> </center> <div id="myDIV" style="padding: 10px 30px;"> <form action="result.php" method="post" id="form">  </form> </div> <script> function myFunction() { var x = document.getElementById("myDIV");     var b = document.getElementById("mybut");     var x = document.getElementById("myDIV"); if (x.style.display === "none") {  b.style.visibility = 'hidden'; x.style.display = "block"; startTimer(); } } window.onload = function() {   document.getElementById('myDIV').style.display

How to create event time(Timmer) in PHP and Javascript?

Create event time(Timmer) in PHP and Javascript. <?php  /* date_default_timezone_set('Asia/Calcutta'); $timestamp = time(); */ //set hours according to the India time $date = '2021-09-28'; $hour = '13'; $minutes = '14'; $seconds = '0'; ?> <div id="timer"></div> <script> //task: get timer details from the previous section and assign them to variables.  //tip, these are associative arrays accessed as $myArray['data']  const countDownDate = <?php   echo strtotime("$date $hour:$minutes:$seconds" ) ?> * 1000; let timeNow = <?php print(time()) ?> * 1000; // Every second, the countdown will be updated. let i = setInterval(function() {  timeNow = timeNow + 1000; // Calculate the time between now and the end of the countdown.   let dist = countDownDate - timeNow; // Calculate the number of days, hours, minutes, and seconds in days, hours, minutes, and seconds. let numOfDays = Math.floor(dist

How to create quiz timer or time countdown in PHP and Javascript?

Create quiz timer or time countdown in PHP and Javascript.  <!DOCTYPE html> <html lang="en"> <body> <center> <div class="time" id="navbar">Time left :<span id="timer"></span></div> <button class="button" id="mybut" onclick="myFunction()">START QUIZ</button> </center> <div id="myDIV" style="padding: 10px 30px;"> <form action="result.php" method="post" id="form">  </form> </div> <script> function myFunction() { var x = document.getElementById("myDIV");     var b = document.getElementById("mybut");     var x = document.getElementById("myDIV"); if (x.style.display === "none") {  b.style.visibility = 'hidden'; x.style.display = "block"; startTimer(); } } window.onload = function() {   document.getElementByI

How to play youtube video on website with youtube link in PHP?

YouTube video on website with youtube link in PHP. <?php $topic_youtube_link = 'https://www.youtube.com/embed/vLFi-ODflLI'; $ytarray=explode("/", $topic_youtube_link); $ytendstring=end($ytarray); $ytendarray=explode("?v=", $ytendstring); $ytendstring=end($ytendarray); $ytendarray=explode("&", $ytendstring); $ytcode=$ytendarray[0]; ?> <ifr ame class="play-youtube" src="https://www.youtube.com/embed/<?php echo $ytcode; ?>"  title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <?php

How to add custom meta value in edit order page in Woo-commerce in Wordpress?

Add custom meta value in edit order page in Woo-commerce in Wordpress?  //===============add meta data on edit order page ========================= /**  * @param $item_id  * @param $item  * @param $product   Product  */ function wpcodekit_order_meta_customized_display( $item_id, $item, $product ) { global $woocommerce, $post;     /*     *  The default key to "$all_meta_data" can be: _qty,_tax_class,_line_tax,_line_tax_data,_variation_id,_product_id,_line_subtotal, _line_total,_line_subtotal_tax     */     $all_meta_data = get_metadata( 'order_item', $item_id, "", "" );   //print_r($product); echo $product->get_id(); echo $order_id = $post->ID; /*  $order = new WC_Order($post->ID); //to escape # from order id  echo $order_id = trim(str_replace('#', '', $order->get_order_number())); */     ?>     <div class="order_data_column" style="width: 50%; padding: 0 5px;">         <h4>&

How to upload file in selected folder in PHP in Wordpress?

Upload file in selected folder in PHP in Wordpress.     <?php    //echo $folder =  get_stylesheet_directory_uri();   // echo $_SERVER["DOCUMENT_ROOT"];  extract($_POST);  global $wpdb;  if(isset($_POST['submit'])){   $filename = $_FILES["file"]["name"]; $ext = pathinfo($filename, PATHINFO_EXTENSION); $encrypt_file= md5(str_replace(" ", "_", $filename).date("Y-m-d-h-i-s")); $realpath = $encrypt_file.'.'.$ext;    $tempname = $_FILES["file"]["tmp_name"];    echo $folder =  $_SERVER["DOCUMENT_ROOT"]."/raising/wp-content/themes/twentytwenty-child/img/".$realpath;    //echo $folder =  get_stylesheet_directory_uri()."/img/".$filename;    move_uploaded_file($tempname,$folder);        } if(!empty($folder)){ ?> <img src="<?php echo get_stylesheet_directory_uri()."/img/".$realpath; ?>" width="400" height="400&qu

How to get product categories in product loop in Woo-commerce?

Get product categories in product loop in Woo-commerce. add_action('woocommerce_shop_loop_item_title', 'pendingcategory');     function pendingcategory(){ global $product; $id = $product->get_id(); $terms = wp_get_post_terms( $id, 'product_cat' ); foreach ( $terms as $term ) { $categories[] = $term->slug; } if ( in_array( 'pending', $categories ) ) {   echo 'Pending'; } }   

How to add "wp_editor" in custom form in Wordrpess?

Add "wp_editor" in custom form in Wordrpess. if(isset($_POST['submit'])){ print_r($_POST); } $editor_id = 'custom_editor_box'; $uploaded_csv = 'hello'; ?> <form action="" method="post"> <?php  wp_editor( $uploaded_csv, $editor_id ); ?> <input type="submit" value="submit" name="submit"> </form> <?php

How to build a tree from a flat array in PHP>

Build a tree from a flat array in PHP   $hello = array   (   array("ID" => "1","student" => "Jassi","marks" => "80","parent_id" => ""),   array("ID" => "2","student" => "Golu","marks" => "80","parent_id" => "1"),   array("ID" => "3","student" => "Jassi","marks" => "80","parent_id" => "1"),   array("ID" => "4","student" => "Jai","marks" => "90","parent_id" => "1"),   array("ID" => "5","student" => "Jassi","marks" => "85","parent_id" => "1"),   array("ID" => "6","student" => "Ravinder","

How to get PHP array group by key value?

“PHP array group by key value" $hello = array   (   array("ID" => "1","student" => "Jassi","marks" => "80","parent_id" => ""),   array("ID" => "2","student" => "Golu","marks" => "80","parent_id" => "1"),   array("ID" => "3","student" => "Jassi","marks" => "80","parent_id" => "1"),   array("ID" => "4","student" => "Jai","marks" => "90","parent_id" => "1"),   array("ID" => "5","student" => "Jassi","marks" => "85","parent_id" => "1"),   array("ID" => "6","student" => "Ravinder","mar

How To Add (Create) Pagination in WordPress?

 Add (Create) Pagination in WordPress. <style> .cus_pagination ul li .page-numbers {     background: white;     padding: 7px 11px;     margin-left: 8px;     text-decoration: none;     border: 1px solid black;     color: #000; } .cus_pagination ul {     display: flex; } .cus_pagination span.page-numbers.current {     background: #000;     color: white; } </style> <?php global $wpdb; // QUERY HERE TO COUNT TOTAL RECORDS FOR PAGINATION  $cars = array   (   array("student" => "Jassi","marks" => "80"),   array("student" => "Jai","marks" => "90"),   array("student" => "Golu","marks" => "85"),   array("student" => "Ravinder","marks" => "30"),   array("student" => "Mukesh","marks" => "45"),   array("student" => "Ankush","

How to add to cart product with ajax in woocommerce?

Add to cart product with ajax in woocommerce (Without Refresh page). <script> jQuery(document).ready(function($) {     $('.wishlist_add_to_cart').on('click', function(e){      e.preventDefault(); $('.wishlist_preloader').css('visibility','visible');     $thisbutton = $(this),                 $form = $thisbutton.closest('form.cart'),                 id = $thisbutton.val(),                 product_qty = $form.find('input[name=quantity]').val() || 1,                 product_id = $(this).data('product-id');                 variation_id = $form.find('input[name=variation_id]').val() || 0;     var data = {             action: 'ql_woocommerce_ajax_add_to_cart',             product_id: product_id,             product_sku: '',             quantity: product_qty,             variation_id: variation_id,         };     $.ajax({             type: 'post',             url: wc_add_to_cart_params.ajax

How to get product detail from product id in woo-commerce?

Get product detail from product id in woo-commerce.                     $product_id = $result->post_id; $product = wc_get_product( $product_id ); $product_link = get_permalink( $product->get_id() ); // Get Product ID    $product->get_id();    // Get Product General Info    $product->get_type(); $product->get_name(); $product->get_slug(); $product->get_date_created(); $product->get_date_modified(); $product->get_status(); $product->get_featured(); $product->get_catalog_visibility(); $product->get_description(); $product->get_short_description(); $product->get_sku(); $product->get_menu_order(); $product->get_virtual(); get_permalink( $product->get_id() );    // Get Product Prices    $product->get_price(); $product->get_regular_price(); $product->get_sale_price(); $product->get_date_on_sale_from(); $product->get_date_on_sale_to(); $product->get_total_sales();    // Get Product Tax, Shipping & Stock    $product-

How to add google reCAPTCHA in form in PHP?

Add google reCAPTCHA in form in PHP <html> <head>   <script src='https://www.google.com/recaptcha/api.js' async defer></script> </head> <body> <?php  if(isset($_POST['submit'])){ $captcha;         if(isset($_POST['g-recaptcha-response'])){           $captcha=$_POST['g-recaptcha-response'];         }         if(!$captcha){           echo 'Please check the the captcha form.';           exit;         }         $secretKey = "<!==== Secret key ====!>";         $ip = $_SERVER['REMOTE_ADDR'];         // post request to server         $url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) .  '&response=' . urlencode($captcha);         $response = file_get_contents($url);         $responseKeys = json_decode($response,true);         // should return JSON with success as true         if($responseKeys["success"]) {      

How to make a section sticky in specific div (Section) in HTML/CSS?

Make a section sticky in specific div (Section) in HTML/CSS. <style> .scrollsec {     height: fit-content;     line-height: 50px;     margin-top: 10px;     font-size: 30px;     padding-left: 10px;     position: -webkit-sticky;     position: sticky;     top: 104px; } </style>

How to create parallax effect in website?

Create parallax effect in website. <!DOCTYPE html> <html class="no-js" lang="en"> <head> <meta charset="utf-8">  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=500" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.8/ScrollMagic.js" integrity="sha512-UgS0SVyy/0fZ0i48Rr7gKpnP+Jio3oC7M4XaKP3BJUB/guN6Zr4BjU0Hsle0ey2HJvPLHE5YQCXTDrx27Lhe7A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <style> .section-wipes {     height: 100%;     width: 100%;     background-image: none; } b {     color: green;     font-size: 44px;     display: flex;     margin: auto;     align-items: center;     justify-content: center;     align-items:

How to create Sign-In profile and Sign-Out mini Drop-Down?

 function shortcut_menu(){ ?> <style> .cus-dropbtn {     color: black;     padding: 16px;     border: none;     background: white !important;     text-decoration: none !important;     font-size: 15px !important;     text-transform: capitalize; } .cus-dropdown {     position: relative;     display: inline-block;     height: 32px; } .cus-dropdown-content {     display: none;     position: absolute;     background-color: #f1f1f1;     min-width: 160px;     box-shadow: 0px 8px 16px 0px rgb(0 0 0 / 20%);     z-index: 120;     top: 33px; } .cus-dropdown-content a {   color: black;   padding: 12px 16px;   text-decoration: none;   display: block; } .cus-dropdown-content a:hover {background-color: #f1f1f1;} .cus-dropdown:hover .cus-dropdown-content {display: block;} .cus-dropdown:hover .cus-dropbtn {background-color: white;} .cus-dropdown-content:after { bottom: 100%; left: 50%; border: solid transparent; content: ""; height: 0; width: 0; position: absolute;

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=&

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 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){

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: trans

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();              });

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