28 October 2019

How to use PHP explode() Function (After comma)?

How to use PHP explode() Function (After comma)?

<html>
<body>

<?php
$str = "Hello,bro,how,are,you,what,are,you,doing";
print_r (explode(",",$str));
?>

</body>
</html>

16 October 2019

How to get woocommerce products in loop ?

get woocommerce products in loop 
with shortcode

function crousalproducts(){



?>
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 12
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>
</ul><!--/.products-->
<?php


}
add_shortcode( 'crousal', 'crousalproducts' );

12 October 2019

How to Update Custom Cart Count (or any HTML) after AJAX Add to Cart in WooCommerce

 Update Custom Cart Count (or any HTML) after AJAX Add to Cart in WooCommerce






function totalcartqty(){


?>
<div class="header-cart-count"><?php echo WC()->cart->get_cart_contents_count(); ?></div>
<?php
}

add_action('wp_head','totalcartqty');

add_filter( 'woocommerce_add_to_cart_fragments', 'iconic_cart_count_fragments', 10, 1 );

function iconic_cart_count_fragments( $fragments ) {
   
    $fragments['div.header-cart-count'] = '<div class="header-cart-count">' . WC()->cart->get_cart_contents_count() . '</div>';
   
    return $fragments;
   
}

How to remove the product rating display on product loops in woocommerce?




// Remove the product rating display on product loops



remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );

10 October 2019

How to choose two dates (date range) from text field?

Choose two dates (date range) from text field




<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-date-range-picker/0.20.0/jquery.daterangepicker.min.js'></script>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/jquery-date-range-picker/0.20.0/daterangepicker.min.css'>

<script type="text/javascript">
$(document).ready(function() {
  $('#date-range-filter').dateRangePicker({
    format: 'DD/MM/YYYY',
    getValue: function() {
      if ( $('#date-from').val() && $('#date-to').val() ) {
        return $('#date-from').val() + ' to ' + $('#date-to').val();
      }
      else {
        return '';
      }
    },
    setValue: function(daterangepicker, from, to) {
      $('#date-from').val(from);
      $('#date-to').val(to);
    }
  });
});
</script>



</head>
<body>
<form action="" method="post">
<span id='date-range-filter'>
  From: <input id='date-from'>
  To: <input id='date-to'>
</span>
<input type="submit" name="submit" value="Submit">
<form>
</body>
</html>

How to pick date(Date Picker) from text field with placeholder in jquery?

 pick date(Date Picker)  from text field with placeholder in jquery




<html>
<head>

  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#datepicker" ).datepicker({ dateFormat: "dd-mm-yy" });
  } );
  </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker" placeholder="Choose date"></p>


</body>
</html>

How to use jquery on checkbox in worpdress ?

<html lang="en">
<head>
<meta charset="utf-8">
<title>Check the Status of Checkboxes</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('input[type="checkbox"]').click(function(){
            if($(this).is(":checked")){
                alert("Checkbox is checked.");
            }
            else if($(this).is(":not(:checked)")){
                alert("Checkbox is unchecked.");
            }
        });
    });
</script>
</head>
<body>
    <p><input type="checkbox"> Check or uncheck the checkbox to get the status.</p>
</body>
</html>

04 October 2019

How to create vertical hamburger menu in wordpress?(Collabse Menu)

create vertical hamburger menu in wordpress?(Collabse Menu)





<html>
<head>
<style>
header#masthead {
    display: none;
}
footer#colophon {
    display: none;
}
.leftside {
    background-color: red;
    width: 20%;
    height: 100vh;
    position: absolute;
    z-index: 1;
    top: 0%;
    bottom: 0%;
    left: -20%;
}
.mainbox{
width:100%;
height:100vh;
background-color:blue;
display:flex;
align-item:center;
justify-content:center;
position:absolute;

}
.innerbox{
border:2px solid black;
width:95%;
height:95vh;
margin:auto;
position:relative;


}
input.bottonleft {
    color: wheat;
    background: #31a529;
    position: absolute;
    top: 0;
    left: 0;
margin:10px;


}
input.bottonx {
    color: wheat;
    background: #8c6767;
    position: absolute;
    top: 0;
    right: 0;
    margin: 12px;
    margin-top: 30px;
}

.blue{

left:0%;
transition:all 0.8s;

}

.green{

padding-left:20%;
transition:all 0.8s;

}
.pink{

left:-20%;
transition:all 0.8s;


}

.yellow{

padding-left: 0%;
transition:all 0.8s;

}

</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
  $(".bottonleft").click(function(){
$(".leftside").addClass("blue");
$(".mainbox").addClass("green");
  $(".leftside").removeClass("pink");
  $(".mainbox").removeClass("yellow")
  });


  $(".bottonx").click(function(){
$(".leftside").addClass("pink");
$(".mainbox").addClass("yellow");
  $(".leftside").removeClass("green");
  $(".mainbox").removeClass("blue");

  });
  });



</script>
</head>
<body>
<div class="leftside">
<input type="button" name="buttonx" class="bottonx" value="X"></div>
<div class="mainbox">
<div class="innerbox">
<input type="button" name="button" class="bottonleft" value=">">

</div>
</div>
</body>
</html>

03 October 2019

02 October 2019

How to use properly search ajax in wordpress?

use properly search ajax in wordpress


Use in html file 

<html>
<head>

<style>
.sec {
    width: 223px;
    height: 41px;
    border: 1px solid #54595f;
margin-bottom:4px;
}
</style>
<script src="<?php echo plugin_dir_url(__FILE__);?>js/jquery.min.js" type="text/javascript"></script>
<script>
jQuery(document).ready(function($){
$(".filter").bind("keyup change", function() {


var ajaxurl = $(".ajaxurl").val();
var bylocation = $("#by-search").val();

var data = {
'action': 'showloactions',
'bylocation': bylocation,
};

jQuery.post(ajaxurl, data, function(response) {
$(".wrapper").html(response);
console.log(response);

});
});
});
</script>
</head>
<body>
<form action="" method="post">
<input type="text" name="search" class="filter" id="by-search">
<input type="hidden" class="ajaxurl" value="<?php echo admin_url( 'admin-ajax.php' ) ;?>">

</form>
<div class="wrapper">

</div>
<?php
//showloactions();

      ?>
</body>
</html>




Use in main plugin file 



 function showloactions(){

 $bylocation = $_POST['bylocation'];
 if(!$bylocation == ""){
        global $wpdb;
        global $wpsite;
$lacationtable = $wpdb->prefix.$wpsite."_locations";
        $result = $wpdb->get_results ( "SELECT * FROM $lacationtable where address LIKE '%$bylocation%'" );
        foreach ( $result as $print )   {
         
?>
<div class="sec"><?php echo $print->city; ?></div>
            <?php
}
}
else{

echo "Not Found";

}

die();

}
add_action('wp_ajax_showloactions', 'showloactions');
add_action('wp_ajax_nopriv_showloactions', 'showloactions');



01 October 2019

How to enqueue script and css file in child-theme and main plugin file in worpress?

enqueue script and css file in child-theme or main plugin file in worpress



FOR Child theme


function theme_js() {
wp_enqueue_script( 'theme_js', get_stylesheet_directory_uri() . '/js/custom.js', array( 'jquery' ));
}

add_action('wp_enqueue_scripts', 'theme_js');



FOR main plugin file 


function ecom_scripts(){
wp_enqueue_script("jquery");
wp_enqueue_script( 'foundation-script', plugins_url('/slider/foundation.min.js', __FILE__));
wp_enqueue_script( 'slick-script', plugins_url('/slider/slick.min.js', __FILE__));
// wp_enqueue_style( 'foundation-style', plugins_url('/slider/foundation.css', __FILE__));
wp_enqueue_style( 'slick-style', plugins_url('/slider/slick.css', __FILE__)); 
    wp_enqueue_script( 'ecom-script', plugins_url('/js/custom.js', __FILE__));
wp_localize_script( 'ecom-script', 'myajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
wp_enqueue_style( 'ecom-style', plugins_url('/css/stylesheet.css', __FILE__));


}
add_action("wp_enqueue_scripts","ecom_scripts");

How to get next 7 days from current day in php ?

Get next 7 days from current day in php 


global $wpdb;
global $wpsite;
$cd = date('d-m-Y');
$nd = date('d-m-Y', strtotime("$cd +".$oid." day"));
$begin = new DateTime($cd);
$end = new DateTime($nd);
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
$i = 1;
foreach ($period as $dt) {
$dt->format("D d-m-Y");
$day = $dt->format("D");
$daynum = $dt->format("d");
echo '<div><span>'.$daynum.' '.$day.'</span></div>';
$i++;
}

How to extract values from textfield for php?

extract values from textfield for php



<?php



extract($_POST);




?>

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...