Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

How to use xampp for php

Xampp is full server package of to start working with the php. It contains the Apache, Mysql, PHP and Perl. For start PHP it is a good platform, it is quite easy to user and install. You can download download the xampp form it official website. For window you can download the .exe file of the xampp and after download by clicking the .exe file you can start installation.

This tutorial is the answer of all there questions:-

- How to use xampp for php?
- How to run xampp localhost?
- How to use xampp for php and mysql?
- How to use xampp mysql?
- How to use xampp to host a website?




Xampp installaion

1. Click the .exe file and instllation start.
2. Install the xampp in the drive where not your windows installed. (In case of window crash or reinstall you can loose your xmapp server php project files.)
3. For example my window is installed in the drive C so i installed the Xampp in the D: drive.
4. You can select also a folder/ directory for its installation.
5. If you only select the D drive then it will install the xampp in the directory xampp and the location will be D://xampp
6. After installation you will get the xampp control icon on your desktop.
7. If not get the xampp control icon on your desktop please got to the directory where you install the xampp and can get the control icon, from here you can copy the xampp-control.exe and can paste shortcut on your desktop or any other location.

8. Now after click on the xampp control icon a xampp window will open where you can start the Apache server and the MySql database to start the xampp for to work on PHP. If in case the Apache not start that can be cuse of the busy port, commonly the skype installed system not allow to start the Apache. For that case use sign-out skype and quit skype and try to start Apache again. There is another reson can the IIS running in the window you can stop the IIS and can try again to start IIS. Here is the view of the xampp control panel before start Apache and Mysql.



9. Xampp Control after start Apache and Mysql. As you can see Apache and MySql marked green it indicate the running successfully.


10. Now after start Xampp need to know where can crate the PHP files. Now you can create you php file in the D://xampp/htdocs directory. But it will be good if you create you own new directory inside the D://xampp/htdocs/my-project now the 'my-project' is my new PHP project inside the xampp server.


11. In the 'my-project' directory now you can create you php file. I am going to create a file withe name of the 'first-file.php'.



12. In you 'first-file.php' you can add you HTML and PHP code. Here i use a HTML tag h1 with some string and a PHP block <?php ?> printing some string using the echo.

<h1>First PHP File</h1>
<?php
echo "This is my first php file.";
?>


13. Now time to execute you php file and view the output of the PHP code. But question is how to execute and view you PHP file. It is quite very easy before view the output make sure your Apach and Mysql still running in side the xampp control panel. After just open any browser Chrome, miaill or safari etc. and enter this url htt;//localhost/my-project/first-file.php. As you hit this url in the address bar of your browser the php will execute on PHP compiler inside the xampp and will return the output in the form of the html text immediate browser will show this output.



14. Accessing MySql datbase using the xampp, use this url http://localhost/phpmyadmin and open in your browser and you will get the phpmyadmin running for you.



15. Here is the link of free online PHP course easy to learn and understand just click and proceed.



PHP Syntax or Code


Php Syntax or code are the php script text, which execute on the php compiler/server and after execution it returns the output in HTML text and send back to the browser and this HTML output can be visible in the any browser. Php syntax have statement, variables and methods like other programming languages. PHP File Extension To save the php document '.php' extension required. you can name your document and in end of the  file user the '.php' extension using this extension the server will identify and execute the php file. here some examples for file naming:- loginForm.php registration_form.php forgot-password.php template1.php MyClass.php PHP block  PHP block is the collection of the angle braces, question marks and php text written in specific arrangement <?php ?>. 
  • To place the php script in the document we need to user the php block <?php ?>.
  • PHP blocks can be written anywhere in the document.
  • PHP use these php block because it easy to embed within HTML text and easy to identify by the server/compiler where exact php code in the document.
  • One necessary thing to understand we can also write the pure HTML code in the php document. file will execute on server.
  • Php code embed within the HTML text the design part of the php web page all are HTML and the server execution output is also HTML so finally a full HTML showed by browser.
  • So browser only hold the html not the php just browser show the server return html.
<!DOCUMENT html> <html> <body> <h1>My First PHP document</h1> <?php echo "String Print"; ?> </body </html> PHP Comments A comment is instructions or can be note about the program which can be written within the php block. Comments are not execute on the server/compiler. Sometime php scripts are also commented as references but not execute on execution time. Comments are a powerful reminder source of the instructions, notes and references. Here two types of the comments in the php first is single line and second is the multi-lines. It easy to understand that single line comments are used to comment the text in the single line in case you want to comments the multi-lines you can use the multi line comment. <?php // THIS IS A SINGLE LINE COMMENT /* THIS IS A MULTI-LINES COMMENT USE TO COMMENT THE MULTIPLE LINES THESE TEXT NOW NOT EXECUTE ON SERVER */ // ALSO CAN COMMENT THE PHP SYNTAX // echo "PRINT STATEMENT"; ?> PHP Case Sensitivity In some of the cases php is case sensitive but here some of the things e.g. echo, if, else, while etc. and user defined functions are not case sensitive. <!DOCUMENT html> <html> <body> <?php ECHO "Print  String!<br>"; echo "Print  String!<br>"; EcHo "Print  String!<br>"; ?> </body </html> Conclusion
  • PHP block is <?php ?>
  • PHP statements end with the semicolon (;).
  • PHP block written in the PHP block.
  • PHP document should be save in the .php file extension.
  • PHP Block embed within the HTML.
  • PHP document can have only HTML tags.
  • PHP document can have only php script.
  • PHP document can have both HTML tags and PHP scripts.
  • PHP document execute only on the server.
  • PHP after execution on server return HTML.
  • PHP scripts execute one by one line on the server.
  • PHP is server side web development language.
  • PHP can be use as OOPS or without OOPS.
  • PHP can be use as MVC or any other architecture.
  • PHP support multi-line ( /* comments */ ) and single line comments ( // Comments )
  • PHP Case Sensitive in some cases.

Wordpress redirect script after reset password



When we doing the wordpress customization with the user authentication many times we required to redirect the different page redirection instead of the default redirection in the after a user login successful. We can easily do this using some hooks here in this tutorial you can see the the user can redirect hot the home page after login so here in the home_url() method you can change the method to your page were you want to redirect the user after login success you your site. You can put the page full url in the columns like 'http://mysitenamehereforexample.com/pagename' instead of the home url method and put this below method in your theme function file. So when you site load the function file load with the theme load and this below hooks will work for the redirect after login. In case this redirect not work it means here some more hooks or php script written in the theme that conflicting with this hook. then you need to find out in your theme and need to make necessary changes.

function wpse_lost_password_redirect() { wp_redirect( home_url() ); exit; } add_action('password_reset', 'wpse_lost_password_redirect');

Install Ioncube load in Godaddy WHM VPS hosting

To install the IonCube loader in Godaddy VPS hosting. First you need to Shell root access of your server you need to follow the below stepls:



1. Give the root access to your user 'hostusername' in WHM
    This is the username of the hosted site on you WHM account
2. In 'WHM' got to 'EasyApache' then got to 'Exhaustive Options' the select the IonCube Loaders
3. Open Shell via Putty
4. Login as the normal user you have 'hostusername' and  this 'thisuserpassword'
5. After login success use the below command to switch the root user (remember this command should only run as root user.)

/scripts/phpextensionmgr install IonCubeLoader

It will show the install success message in shell but confirm in you php program you can check using the phpinfo() method.

How to run your first php program in xampp on Window operating system

This tutorial all about how to run your first php code in xampp. To start with this tutorial make sure you have already installed xampp one of your drive. After install xampp there will be a shortcut icon on desktop for xampp control panel. if don't get further i'll describe how get this icon. After installation you can see a 'xampp' named directory in your drive or defined location. Now second confirm apache and mysql is running in the xampp control panel. For example if you installed the xampp in D drive you can see 'D:\xampp' sometime by mistake beginners create a directory 'xampp' in drive D before installation. So it looks like 'D:\xampp\xampp'.  Here in this directory you can get your 'xampp control' icon as well. So double check where the exactly xampp installed. After open the 'xampp' folder you see list of folder and files now need to open the directory 'htdocs'. In the 'htdocs' you can create a new directory like i am creating  'firstproject'. It will look like: 'D:\xampp\htdocs '

Xampp Control: Here click on 'xampp control' icon to open the panel.




Running Xampp Control:





Directory path.
D:\xampp\htdocs




No time to create a Pph file in the 'firstproject' folder. Create a file name 'new.php' it this directory. We will simple write the php string write script. To write php script we need to user php block '<?php ?>' within it we can write our php script. Here is the code we are going to use in the php file.

<?php
echo "This is simple php script to write string.";
?>

No to see the output we need to type the address 'http://localhost/firatproject/new.php' and we can see the output.


To following these simple steps you can start running your first php script. It is very useful steps to beginners to start with php and xampp server. Xampp X represent Cross platform, A represent Apache web server, M represent MySQL database, P represent PHP and last P represent PEARL packages. So it is a full web serve package.


A Begning with wordpress child theme

Why need to develop child theme?

In this article we discuss how create a child theme in wordpress. How to use of child theme in wordpress and  what points are important in create a child theme in wordpress.  If you can perform simple css change in theme design you can design a child theme.  Creating a wordpress  child theme is very easy  and simple.  Child theme allow you to some changes without  affecting the  original theme script. The  child theme is separate   theme depends on their parent theme mostly functionality.  The child theme allow you to changes  on the theme according to your requirement.  In the child theme possible to all content change according to your need.  In the child theme we are change font color,  size  and different action  on the buttons.  If the parent theme is update in newer version  functionality but no effect on the child theme.  Child theme is performing   adjustment  of   your theme.


 Creating a child theme are  following Example.

In this example we create the  child-theme.   Some simple steps are using to create the child-theme in wordpress.
               
1.  Firstly we install the latest wordpress  theme.
2.  Create a new folder like child-theme in "/wp_content/themes/".
3.  Copy following code in new file style.css in child-theme folder.
               
 /*
Theme Name:  Child-Theme
Theme URI: https://domainname.com
Author: Your NAme 
Author URI: https://my-domain-name-here.org/
Description: Creating my child theme
Version: 1.3
*/


In this code fist line starting with Theme Name.  Theme name is very important line in this code.
Theme name specify in wordpress  what is  name of your theme and after some detail of author  name , author url , theme description and theme version. Take a screen shot  of wp-admin/themes.php  Dashboard page in save screenshot.png and save in child-theme folder. 

4.  After the theme detail  import the style code  in  child theme in style.css

      @import url("../parent-theme/style.css");

We can apply  new css style in child theme page style.css . we can change the theme structure using
change the  adjustments in child theme. Activating theme and uploads a  child theme is no different
from parent theme.


5.  Copy all another important files into parent theme in child-theme (such as header.php, footer.php,
Function.php etc.) . Activate my child theme in / wp-admin/themes.php. Activate theme via Appearances > Themes  page in your WordPress  Dashboard. Child-theme activated in dashboard successfully.  After the theme activate you can see the frontend  design  of child-theme  is  same     parent theme design.

 


Beginners login form development tutorial using PHP script and Mysql Database

Login form is used for  providing  the individual access the computer system.  Login form providing the the security for unauthorized access the website program and server.  Login form  is a process to identify the information into a  system  by a user. Login form providing  the security  our system and website data. Create the login form in HTML is very simple. In the login form below example we use two text fields username, password and login button.

Example

login_form.html

Following  HTML code for the login form.

<html>
    <body>
    <form  action='login_action.php' method='post'>
        <table>
            <tr>
                <td>User Name</td>
                    <td><input type = "text"  name=  "user_name"></td>
           </tr>
                                                                                 
           <tr>
                  <td>Password</td>
                  <td><input type = "password"  name = "password"></td>
                 </tr>
                    <tr>
                      <td><input type  = "submit"  name = "login" value = "Login"></td>
                   </tr>
        </table>
       </form>
     </body>
 </html>             



 Login form action will be performed using phpMyAdmin in managing MySql database.  MySQL  database is very popular open source  SQL database management system.  Firsly  we create the database in phpMyadmin.  After create the database create the table in Mysql database.  In the database table we create three fields id, user_name and  password. After create the table insert value in username and password. Your database is ready to use.

login_action.php

<?php
ob_start();
mysql_connect("localhost", "root", "password");
mysql_select_db("databasename");

if(isset($_POST['login']))
{
    $user_name  =  $_POST['user_name'];
    $password  =  $_POST['password'];
    $login =  "select * from tablename where user_name=       '$user_name' && password= '$password' ";
     $exe = mysql_query($login);
     $rows = mysql_num_rows($exe);

    if($rows == 1)                                                                             
    {
        echo "Login Successfully";
     }
    else
    {
        echo "Invalid Username/Password";
     }
}                                               
?>

  After create the HTML login form we create the login_action.php page. In the login action page
  firstly we start php script for connecting the database table using php  script. When user fill
  the user name and password text fields and click on login button.  The login_action.php page
  will be open.  If your username and password is true  login successfully message display on
  the your screen. If your username and password not matched invalid username and password
  message display on your screen.


 
 


How to develop text SMS sending API script using PHP?

SMS  send  on  mobile  using  sms  API  in PHP

This article based on how to send sms on mobile using PHP.  Short Message Service (SMS) is text
Messaging   service by using mobile and web communication between clients and users.  SMS is mostly  used   application. The sms send using  sms  API  is very easy and send sms quickly.  API's are the most powerful  and reliable way to communicate between two servers.  Send  sms using  API  is  very secure. Using API we are send thousand sms same time. The example  below using API in php.  



message.php
                                  
// Your authentication key
$authKey = "7280A1SXJMbLr54d5d469";

// Multiple mobiles numbers separated by comma
$mobileNumber  =  S_POST[‘mobile’];

// Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "ABCDEF";

// Your message to send, Add URL encoding here.
$message =  S_POST[‘message’];

// Define route
$route = "default";

// Prepare you post parameters
$postData = array(
    'authkey' => $authKey,
    'mobiles' => $mobileNumber,
    'message' => $message,
    'sender' => $senderId,
    'route' => $route
);

// API URL
$url="http://sms-api-website-url-for-request.com/sendhttp.php";

// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postData
    //,CURLOPT_FOLLOWLOCATION => true
));

// Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


// get response
$output = curl_exec($ch);

// Print error if any
if(curl_errno($ch))
{
    echo 'error:' . curl_error($ch);
}

curl_close($ch);

echo $output;

?>
In the above example authentication key is used for login authority in API. Authentication key is unique for every user.  Authentication key is alphanumeric data type. In the mobile parameters we use  mobile number. The multiple  mobile numbers should be separated by comma (,).   In the message parameter we declare our text message. We can send sms on in different languages (such as english,  hindi,  Punjabi  etc.) by using unicode.  Sender ID parameter is show to receiver  will see this as sender's ID.  We are used in  sender ID  six variable character. If your SMS API operator support multiple roots then give one root  name (eg route=1 for  promotional messages and route=4 for transactional SMS).


Example:

form.html
<html>
     <body>
         <form method  = "post"  action = "message.php">
             <table>
          <tr>
                  <td>Mobile</td>
                    <td><input type = "text"  name = "mobile"></td>
                </tr>

               <tr>
                  <td>Message</td>
                    <td><input type = "textarea"  name = "message"></td>
                </tr>
          <tr>
                 <td><input type = "submit"  name = "submit"  value  =  "Submit"></td>
                 </tr>
             </table>
          </form>
       </body>
     </html>

The  example  below contains an HTML form with two input fields and a submit button.First text field is Mobile  field,   Second  message field  declare in the form.  When user fill the text field in  form click on submit button  the data will be send to PHP file .

The URL will look like this:

http://www.your-domain-name.com/message.php

The out will be  show in alphanumeric 24 character like  2548456a582s250001234879. If message not send successfully  you will get the  error message .



How we can send attachment with E-mail using php?

This article based on how to attach file in E-mail form using php. The mail attachment function is used form send some text email message and  attachment file. We can send computer file using email attachment. Some  headers and Multipurpose Internet Mail Extensions(MIME) mail  parts are used for successfully submit the email with attachment. Now a days email is most commonly used. We used mail() function to send the attachment. Firstly we generate  the HTML form.
 HTML form is used  to collect the user Information. Form elements are different types of input elements, such as Name , Email and File.
 
In the  attachment form three  fields are  name,email and file. In the first field fill your name, Second field  your email address and then  third field you can click on browse button to select the file on your computer. In the form tag used "enctype="multipart/form-data" to upload the file. when you fill all the field correctly click on submit button attachment_mail.php page will be open. you can see the  Mail successfully submit on this screen message.Your form detail is successfully submitted and goes to receiver.


Example:
attachment_form.html

<html>
 <body>
  <form method="post" action="attachment_mail.php" enctype="multipart/form-data">
   <table align="center">
      <tr>
         <td>Name</td>
            <td><input type="text" name="name"></td>
        </tr>
       <tr>
          <td>Email</td>
             <td><input type="email" name="email"></td>
        </tr>
        <tr>
          <td><input type="file" name="photo"></td>
         </tr>

        <tr>
   <td colspan="2">
           <center>
            <input type="submit" name="submit" value="Submit">
           </center>
          </td>
 </tr>
 </form>
 </body>
</html>

attachment_mail.php
<?php
if(isset($_POST['submit']))
{
  //Following  code we are used to Upload the file on the server.Name,type, size are attributes for upload file.
  
  $photo = $_FILES['photo']['name'];
  $type = $_FILES['photo']['type'];
  $size = $_FILES['photo']['size'];
  $tmppath = $_FILES['photo']['tmp_name'];
   
  //CHECK THE FILE IS UPLOADED OR NOT 
  //EMPTY FUNCTION CHECK THE ARRAY IS EMPTY OR NOT 
  if(!empty($photo))
  {
    //image is a folder in which you will save image
    move_uploaded_file($tmppath,'image/'.$photo);
    //Send the E-mail script
    $your_message = $_POST['name'];
    $to = "abc@gmail.com"; //Recipient Email Address
    $subject = "Send E-mail with Attachment"; //Subject of Email
    $headers = "From: " . $_POST['email']. "  \r\nReply-To: abc@example.com";
    $random_hash = md5(date('r', time()));
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
    $attachment = chunk_split(base64_encode(file_get_contents('image/'.$photo))); // Set your file path here
    $message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
    $message .= "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";

    //Insert the html message.
    $message .= $your_message;
    $message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
    //include attachment code
    $message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/zip; name=\"photo.png\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
    $message .= $attachment;
    $message .= "/r/n--PHP-mixed-$random_hash--";
    //send the email script
    $mail = mail( $to, $subject , $message, $headers );
    echo $mail ? "Mail successfully submitted" : "Error occurred";
 }
}
?>

In the attachment_mail.php page firstly we upload the file on server code. In this code we declare some attributes are file name (name of the file), file type (determine the file type .jpg, png etc.), file size(check the size of the file in kb,mb etc.). After the attributes  empty function used for check the file is not empty. If the file is not empty we declare a file folder path which you save your  file on the  server. Then mail function is used to send your information and file by email attachment script. Some Parameters are used in mail function (such as $to,$subject,$message,$header). To Parameter is used for recipient email address. Subject parameter is specifies the subject of your  email. Headers parameter are specifies optional headers, like From, Cc, and Bcc.


Hoow to get form data using POST method in PHP

The most important part when dealing with HTML forms .POST method supporting multiple request at same time by HTTP protocol used by www(world wide web).POST method used in same way as the GET method. The POST method is used to send the hidden information for the users on HTML web server. In the POST method we can send large information of data forms.
 
Note: However, there is an 8 Mb max size for the POST method, by default.
(If you want to increase the post_max_size can be changed by setting the post_max_size in the php.ini file). 
EXAMPLE:-
The POST method is very simple to use in the HTML form .The  example below contains an HTML form with two input fields and a submit button:
 
Index.html
 
<html>
    <body>
        <form action="action.php" method="post">
            <p>User Name: <input type="text" name="user_name" /></p>
            <p>Password: <input type="password" name="password" /></p>
              <input type="submit" name="submit" value="Submit" />
        </form>
    </body>
</html>  


When user fill the text field in  form click on submit button  the data will  be send to PHP file called "action.php"
The URL will look like this:
http://www.your-domain-name.com/action.php
 
action.php
 
 <?php
    if(isset($_POST['submit']))
    {
        echo  $user_name = $_POST['user_name'];
        echo  $password = $_POST['password'];
    }
?>
  
The "isset" function used to determine any variable  has been set or not. The built-in $_POST function is used to collect values from a form sent with method="POST". Echo is used for display the form data on HTML web Page. 

Output could be something like this:
User Name
12345678


Woocommerece header cart menu deleting item using ajax

In my previous tutorial i wrote about how to delete item using ajax in the 'CART PAGE'. But in this tutorial i'll teach you how to delete the item from the header cart menu. It will enhance the website functionality if a user can delete the items without going on cart page, it mean user can delete items from any page of website. But it will be more user friendly if deleting from the cart menu using ajax. In the 98% themes there is full page load after deleting the cart ajax men. There is custom made code for you to use and enhance your site functionality.

Here some easy steps for you to develop this script and apply on your website:

1. One is open a PHP file named 'woo-cart.php' from the place '/wp-content/themes/wp_woo_market/framework/functions/' this is the source file of the woocommerce cart menu in the header of the theme in the website.

2. Find the source code of the delete button or icon it is a anchor tag with the href attribute stored the delete script source file for the particular item query strings or url parameters. you can check this:

echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf('<a href="%s" class="remove" title="%s">&times;</a>', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'wpdance' ) ), $cart_item_key );

This is the delete icon code in Woo Market theme. in your theme you can find this or something similar.

3. By commenting this we can backup of this code and write new code for the ajax delete button.

echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf('<a href="javascript:void(0);" class="remove" onclick=removePro(this,"%s"); title="%s">&times;</a>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'wpdance' ) ), $cart_item_key );

This is new delete button code to delete the item with js method that call the ajax to delete item.

4. Now open the 'footer.php' file of the your woo theme now the jquery ajax code should be written in the footer because this script should be on whole the site to call any page. so footer is the best location to place or write this script. And this script should be within the <script> start and end </script> tags. check this script:

function deleteItemCart(e,href){
//alert(href);
jQuery('<img src="<?php echo bloginfo('stylesheet_directory'); ?>/images/ajax-loader.gif">').appendTo(e);
jQuery.ajax({
url:href,
success:function(response){
if(response){
jQuery(e).parent().parent().remove();
jQuery.ajax({
url:'http://www.your-woo-cart-site-name.com/wp-admin/admin-ajax.php?action=update_tini_cart',
success:function(response){
jQuery(".shopping-cart-wrapper").html(response);
}
});
}
}
});
}

5. We need to more script to remove the html elements of item. After ajax delete the page will not reload so we use the client side script to remove the UI of deleted item. This script also written within the script tags.

jQuery(document).ready(function(){
jQuery(document).on("mouseenter",".cart_size",function(){
jQuery(".cart_dropdown").css("display","block");
});
jQuery(document).on("mouseenter",".cart_dropdown",function(){
jQuery(".cart_dropdown").css("display","block");
});
jQuery(document).on("mouseleave",".cart_size",function(){
jQuery(".cart_dropdown").css("display","none");
});
jQuery(document).on("mouseleave",".cart_dropdown",function(){
jQuery(".cart_dropdown").css("display","none");
});
});

6. After uploading this updated script the ajax delete from the cart header menu will work. And user can access this feature.




How to delete items using ajax from cart page in woocommerce woo_market theme

In woocommerce most of the free or premium theme there is no feature to delete items using ajax from the cart page. That can be the reason of loosing lots of business, users never like to reload page again after delete of each item. So a good and user friendly theme should have the ajax delete item and ajax add item feature. But often we see there is the ajax add feature available in most of the the but not have any delete using ajax available in the themes.

We can develop the ajax delete form our cart page using the custom code. it is very easy and it will take some chunks of lines to do this and after we have a user friendly ajax delete functionality. After this user want to stay more on your store and buy more items. And you will definitely glow every day.

To start before you have the access of file manager or ftp your hosted files. There are some simple steps you need to follow.

1. First open the 'cart.php' in the location '/wp-content/themes/wp_woo_market/woocommerce/cart/' and also backup of your file as well.

2. Find the product remove link location you can search of find

echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf('<a href="%s" class="remove" title="%s">&times;</a>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'wpdance' ) ), $cart_item_key );

3. Before write new code to secure your code comment the above mention code and write new code instead of this.  this new code call a js function named (removePro) instead href link of delete cart. check below:

echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf('<a href="javascript:void(0);" class="remove" onclick=removePro(this,"%s"); title="%s">&times;</a>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), __( 'Remove this item', 'wpdance' ) ), $cart_item_key );

4. We need to write a client side script call the ajax to delete items. This ajax generate the delete url and on call it will delete the item. write this script in your 'cart.php' in the bottom of the file and should write within the script tag.

function removePro(e,href){
//alert(href);
jQuery('<img src="<?php echo bloginfo('stylesheet_directory'); ?>/images/ajax-loader.gif">').appendTo(e);
jQuery.ajax({
url:href,
success:function(response){
if(response){
jQuery(e).parent().parent().remove();
jQuery.ajax({
url:'http://www.your-site-name-come-here.com/wp-admin/admin-ajax.php?action=update_tini_cart',
success:function(response){
jQuery(".shopping-cart-wrapper").html(response);
}
});
}
}
});
}

5. Now time to write a another script to delete that html row of the item as well. Because the ajax delete the item from the database and from the server session as well. But this another script will remove the items client side. It should also within the script tag.

jQuery(document).ready(function(){
jQuery(document).on("mouseenter",".cart_size",function(){
jQuery(".cart_dropdown").css("display","block");
});
jQuery(document).on("mouseenter",".cart_dropdown",function(){
jQuery(".cart_dropdown").css("display","block");
});
jQuery(document).on("mouseleave",".cart_size",function(){
jQuery(".cart_dropdown").css("display","none");
});
jQuery(document).on("mouseleave",".cart_dropdown",function(){
jQuery(".cart_dropdown").css("display","none");
});
});

6. Now saving and uploading the custom script you can delete without loading page again and again.







How to develop a Child theme in wordpress

Why need to develop the wordpress child theme?

There are many reasons to develop child theme. There can always a problem with the custom theme or customized theme if we update theme, plugins and wordpress. After updating any of them we loose out custom developed design and functionality. Because we change in the theme files most of the things we done withing the functions.php and style.css or any other files of theme. So when we update a theme, it over write the theme files. so our custom code in the any of the file flushed by update and the custom developed functionality and the custom made design html,css and jquery also flushed by the updates. So the best way to secure our custom made scripts we need to develop the child theme extending out current theme. So when the current theme will update the extended child theme will not over write.

Developing a child theme

We can easily develop the child theme it is very easy to develop. It will take little amount of efforts and your custom design and functionality will be secure forever.  Let start with the any exists theme. I am using the theme name 'mytheme' to extend and the child theme name is 'mychildtheme'. follow the instructions below to develop a child theme:-

1. First create a directory of child theme like 'mychildthme' in the "/wp_content/themes/"

2. Create a style same as we develop for any theme and write about the theme details in comments in top of file
   
/*
Theme Name: My Child Theme
Theme URI: http://nxtut.com/
Author: Daljeet Singh
Author URI: http://nxtut.com/
Description: This is my first child theme
Version: 1.1
*/


3. Import the style of the theme from we and extending it. Use the below code in the style sheet after the theme details section. I am importing the style of 'mytheme' into the 'mychildtheme'

@import url("../mytheme/style.css");

4. Place a screenshot.png of out new theme in the 'mychildtheme'

5. Copy the necessary templates files from your 'mytheme' to 'mychildtheme' like header.php, footer.php, page.php etc. whom you want to overwrite

6. functions.php required the required methods of extended theme to in the 'mychildthme'

7. After that you can see the child theme in the theme section under appearance menu in the admin area.

8. After activating the child theme when you see the fronted it show the same design is workin gfrom we extended the design.

9. If getting any time of php warning of error on page jut need to copy some methods or files in child theme from the parent theme. It happen just because of every parent theme have different specific methods for some special functionality like any widgets, hooks, sidebars,menus, module etc.






Wordress woocommerce fixing toggle issue of menus in the WOO Market Theme in mobile responsive design

To fix the issue of responsive menu toggle in the WOO MARKET theme of woocommerce framework on wordpress theme follow the instruction mentioned below:

1. first open the "main.php" located in the directory "wp-content/themes/wp_woo_market/framework/functions/"

2. Find the html code <div class="wd_vertical_menu col-sm-6 col-xs-24 wd_mega_menu_wrapper">

3. Add the one another class "toggle_active"

4. Now it looks like class="wd_vertical_menu col-sm-6 col-xs-24 wd_mega_menu_wrapper toggle_active"

5. Upload the changes and uploading the updated main.php

6. Now refresh your page properly you can see the menue working properly.

This issues was coming because of the toggle_active call is missing in he source. You can also check the file "\wp_woo_market\js\wd_menu_front.js" and search code "if(jQuery('.wd_vertical_menu').hasClass('toggle_active') || (using_mobile && case_size <= 767) )" as per this code wd_verticle_mnu class element have another class "tootle_active" then it will work as responsive menu in the mobile and tablet screens. You can see there more issues in this theme need to fix to work properly.

Quick Tutorial on How to Create a WordPress website

The website that you’re searching at is installed on WordPress and i got everything for free. On this quick tutorial I’m likely to guidebook you step-by-step regarding how to develop a website making use of WordPress that might search comparable to this site.

1) Website hosting

I recommend using BlueHost website hosting. It's a great internet host for the WordPress computer software since it has every little thing that you must host WP websites (MySQL database, PHP, and so forth.) and so they also advise it as being a WordPress net host ranked #1 correct within the wordpress.org website. I host my 5 big WordPress-powered internet sites with them and possess not experienced any difficulties to date. I have been with them currently for additional than five a long time and am 100% happy with them.

Indeed, you may also go with totally free web hosting, but I really don't suggest that, as WordPress needs a databases to operate and even the most effective free internet hosts have issues with this (this was my very own experience with Freehostia.com, I then went for paid web hosting).

2) Put in WordPress

I recommend putting in WordPress making use of the one-click WP set up function with SimpleScripts in the BlueHost’s cPanel. It is actually simple and quick. Just search for the WordPress icon within the control panel, simply click on it, then fill in each of the particulars and click “Install”. It’s as simple as that.

3) Upload a WordPress Template

Locate a nice WordPress topic to your web site and just upload it for the wp-content/themes/ folder. Then activate it in the WP admin panel - in Look -> Themes.

To locate a WordPress topic for your site I like to recommend you to verify out the high quality WP themes by Themes Websites - you may get use of all their stunning 86 themes from just $5 to $50. They have really great themes and i have also utilized them for many of my assignments. Even this website’s concept is one of their themes. Otherwise you may also hire a website developer to design a custom made WordPress topic to suit your needs - check the Providers page of developer website to see some samples of his function.

4) Modify the Topic

In the event you usually do not want the comments and also the “posted by… on…” exhibited to make your web site not appear similar to a blog, just delete the next from your index.php (as well as delete exactly the same inside the information web page.php and single.php - if you will find these files):

Note: Backup the files of your concept before enhancing it, so that you've the initial documents just in case you do one thing improper.

In the event the topic you are utilizing utilizes a different code, you'll be able to discover someone over a webmaster forum who'll try this for you personally. Or you can also contact me and that i will help you using this. You might also wish to edit some pictures of the concept like e.g. the header image. I've done both of such modifications within the concept of the site - I taken out the feedback and added the text “wordpress.lexty.com” to the header impression. And that is it. You might be done, great luck with your new WordPres site!


Global vs Suparglobals in PHP

The range of the availability or scope of variables are called global of superglobals.

Global

A variable declared can be global using the keyword global. Placing global keyword in the front of a variable change it to as global scope. No it is accessible within a function or within a include file if it is not within file of function. Placing 'global' keyword in front of the and already existing variable tells PHP to use the variable having the name.



<?php
// DEFINE A VARIBLE NAMED $one
$one = 'ONE';
// DEFINE A ANOTHERE VARIABLE NAME $two
$two = 'TWO';

// CREATE A FUNCTION WIT HTHE NAME OF THEST
function test()
{
// USING GLOBAL KEYWORD FIND THE BOTH VARIABLES AVAILBLE IN THIS PROGRAM
global $one, $two;

// PRINT A STRING USIGN THE GLOBAL SCOPE VARIABLE CONCATED WITH THE STRING
echo "Red function has " . $one . " and Green function has " . $two . " Parameters";

}
?>

Superglobals

Superglobals are PHP built in variables or members That have already have global scope they don't have need to add global keyword. There are some superglobals are listed below.




$GLOBALS, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_REQUEST, $_ENV

Fibonacci Series using PHP


Fibonacci Series print the values of the value of current and previous value of the natural numbers it is look like 0 1 1 2 3 5 8 13 it is the linear sequence of the integers these all values follow the the mathematical logic is Fn+1 = Fn + Fn-1



<?php
// DEFINE $i for INITILIZATION
$i = 1;
// DEFINE $a FOR THE STARTING LOOP VALUE
$a = 0;
// DEFINE $b FOR SECON HELPER VALUE
$b = 1;

// START LOOP TO PRINT VALUE
// CONDITION WILL PRINT ONLY 20 VALUES
// LOOP WILL RUN  ONLY 20 TIMES
while($i<=20)
{
// LOOP WILL PRINT THE VALUES HERE
// CONCATINATION SPACE TO DIFFERENCIATE THE VALUES
echo $a . " ";  // 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
// $c IS HELPER VARIABLE STORE THE THIS AND NEXT VALUE
$c = $a + $b; // 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946
// ASSIGN NEXT VALUE TO THE $a
$a = $b; // 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
// ASSIGN THE VALUE OF $C(SUM OF THIS AND NEXT VALUE) TO $B
$b = $c; // 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946
// INCREMENT FOR LOOP
$i++;  // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
}

?>

Students Tech Life