Top Questions:

  • 5 years-11 months

    UI Datepicker be made to disable Saturdays and Sundays with custom date

    • Category : jquery
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    I use a datepicker for choosing an appointment day.I want to exclude Saturdays and Sundays from the available choices. Can this be done? If so, how?

    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <input name="datenew" type="text" id="datepicker">
    <script>
    var unavailableDates = ["21-6-2016","22-6-2016","23-6-2016","24-6-2016"];
    function unavailable(date) {
      var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
        dmy = date.getDate()   "-"   (date.getMonth()   1)   "-"   date.getFullYear();
      var closedDays = [[Saturday],[Sunday]];
     for (var i = 0; i < closedDays.length; i  ) {
        if (day == closedDays[i][0]) {
          return [false];
       }
    
     }
        if (jQuery.inArray(dmy, unavailableDates) == -1) {
            return [true, ""];
        } else {
            return [false, "", "Unavailable"];
        }
    }
    jQuery(function() {
      jQuery( "#datepicker" ).datepicker({    
        changeMonth: true,
        changeYear: true,
       dateFormat: 'dd MM yy',   
        autoclose: true,
        minDate:  2,
        firstDay: 1,
        beforeShowDay: unavailable
      });
    
    });
    </script>
  • 3 years-4 months

    Display limited words

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Display limited o of word from a string using this code

    echo mb_strimwidth('It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English', 0, 50, "...");
     
  • 3 years-4 months

    Last Week Start And End Date

    • Category : php
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Get last week start and end date in php

    $previous_week = strtotime("-1 week  1 day");
    
    $start_week = strtotime("last sunday midnight",$previous_week);
    $end_week = strtotime("next saturday",$start_week);
    
    $start_week = date("Y-m-d",$start_week);
    $end_week = date("Y-m-d",$end_week);
    
    echo $start_week.' '.$end_week ;
     
  • 5 years-11 months

    woocommerce cart not working for without login

    • Category : wordpress
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    I am fairly new to woocommerce and although the other day the add to cart and cart page was displaying fine. I am now finding that going to my cart page brings up a blank page.

    add this code in function.php
    add_filter('woocommerce_add_to_cart', 'custome_add_to_cart');
    function custome_add_to_cart() {
        global $woocommerce;
     $woocommerce->session->set_customer_session_cookie(true);
    }
     
  • 5 years-11 months

    woo-commerce cart item session start and destroy after 30 Min.

    • Category : wordpress
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    woo-commerce cart item session start and destroy after 30 Min

    <?php
    
    global $woocommerce;
    if (!isset($_SESSION['EXPIRES']) || $_SESSION['EXPIRES'] < time()) {
     $woocommerce->cart->empty_cart(); 
    } else {
      $_SESSION['EXPIRES'] = time() 1800;
    }
    
  • 3 years-4 months

    Print Data using Ajax

    • Category : ajax
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    print your custom data or field using ajax

    function printinvoice(id){
         $.ajax({
           url: "sample.php",            
                type: "POST",
           data: "print_id=" id,
          success: function(data) {
         newWin= window.open();
                            newWin.document.write(data);
                            newWin.document.close();
                            newWin.focus();
                            newWin.print();
                             newWin.close();
          },
      error: function() {
         
          }
       }); 
    }
  • 5 years-11 months

    How to add the media uploader in wordpress plugin

    • Category : php
    • Location : Chandigarh, India
    • Posted On :
    • Posted by : Vikas

    When i click the first upload field (uploading process are success) after insert into post that corresponding media url is appear in the second field not in first. I am not sure where is the problem any suggestion would be great.

    <?php
    wp_enqueue_script('jquery');
    // This will enqueue the Media Uploader script
    wp_enqueue_media();
    ?>
        <div>
        <label for="image_url">Image</label>
        <input type="text" name="image_url" id="image_url" class="regular-text">
        <input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image">
     </div>
    <script type="text/javascript">
    
    jQuery(document).ready(function($){
        $('#upload-btn').click(function(e) {
            e.preventDefault();
            var image = wp.media({ 
                title: 'Upload Image',
                // mutiple: true if you want to upload multiple files at once
                multiple: false
            }).open()
            .on('select', function(e){
                // This will return the selected image from the Media Uploader, the result is an object
                var uploaded_image = image.state().get('selection').first();
                // We convert uploaded_image to a JSON object to make accessing it easier
                // Output to the console uploaded_image
                console.log(uploaded_image);
                var image_url = uploaded_image.toJSON().url;
                // Let's assign the url value to the input field
                $('#image_url').val(image_url);
            });
        });
    });
    </script>
    
    
    
    // UPLOAD ENGINE
    function load_wp_media_files() {
        wp_enqueue_media();
    }
    add_action( 'admin_enqueue_scripts', 'load_wp_media_files' );
     
  • 3 years-4 months

    Forgien Key Mysql

    • Category : mysql
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Foreign Key integration between two tables

    $id='15';
    mysql_query("select table1.column1,table1.column2,table1.column3, table1.column4, table2.column1, table2.column2, table2.column3, from table1name table1, table2name table2 where table2.column1=table2.column1 and table1.column1='$id'");
     
  • 3 years-4 months

    Custom Register Button

    • Category : wordpress
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Its helps to register user in your wordpress site.Before use go to -> settitng -> General setting -> Register anyone -> role(Subscriber).

    <?php echo apply_filters( 'register', sprintf( '<a class="btn btn-danger" href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ) ); ?>
     
  • 3 years-4 months

    Multiple file Upload

    • Category : wordpress
    • Location : Chandigarh
    • Posted On :
    • Posted by : Guley

    Upload multiple video file and store its in database using this code.

    <?php
    $server_url="http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"].'?').'/';
    $path = preg_replace('/wp-content.*$/','',__DIR__);
    $path = preg_replace('/wp-content(?!.*wp-content).*/','',__DIR__);
    include($path.'wp-load.php');
    /******Database Connect end*******/
    if(isset($_POST['add']))
    {
    $_FILES["fileToUpload"]["name"];
    if ( ! function_exists( 'wp_handle_upload' ) ) {
    require_once( ABSPATH . 'wp-admin/includes/file.php' ); }
    $upload_overrides = array( 'test_form' => false );
     $files = $_FILES["fileToUpload"]; 
        foreach ($files['name'] as $key => $value) {           
                if ($files['name'][$key]) {
                    $file = array(
                        'name' => $files['name'][$key],
                        'type' => $files['type'][$key],
                        'tmp_name' => $files['tmp_name'][$key],
                        'error' => $files['error'][$key],
                        'size' => $files['size'][$key]
                    );
    
                   $_name = $file['name'];
                   $f_name =  explode('.', $_name);
                    $rand = rand(0000,9999);
                   $addname = $f_name['0'].$rand;
                   $total_name = $addname."." .$f_name['1'];
    
                  $insertname[] = $total_name;
    
    
    
                   $file_s = array( 'name' =>  $total_name,
                        'type' => $files['type'][$key],
                        'tmp_name' => $files['tmp_name'][$key],
                        'error' => $files['error'][$key],
                        'size' => $files['size'][$key]
                    );
    
    
    
    
                 
    
                    
                        $newupload = wp_handle_upload($file_s,$upload_overrides);
                      $patoooooooooh[] = $newupload['url'];
                   
                }
            }
    $nname=implode("&",$patoooooooooh);
    mysql_query("insert table_name (`column_name`) values ('$nname')");
    }
    ?>
    /*****Php Code end and html start*****/
    <form class="form-horizontal" method="post" enctype="multipart/form-data">
    <input type="file" name="fileToUpload[]" id="fileToUpload" class="add_file">
    <div class="demo">
    </div>
    <button name="add" type="submit">Add</button>
    </form>
    /********Html End & jquery Start**************/
    
    <script>
    $(document).ready(function() {
    // $('.add_field_button').keyup(function(e){
      var rand=Math.random();
    $(document).on('change','.add_file',function(e){
      //on add input button click
            e.preventDefault();
                $('.demo').append("<div class='sas'><br/><input type='file' name='fileToUpload[]' class='add_file' ><a href='#' class='remove_field'><i class='fa fa-trash-o'></i></a></div>"); //add input box
        });
      $('.demo').on('click', '.remove_field', function(e) {
        $(this).closest('.sas').remove();
      return false;
    });
    });
    </script>