Top Questions:

  • 5 years-11 months

    woocommerce backend add items in new or edit orders

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

    If you need to change item product prices in Woocommerce Backend Order. Please use the following hook or code

    add_action( 'woocommerce_ajax_add_order_item_meta', 'VP_set_item_quantity', 99, 3 );
    function VP_set_item_quantity( $item_id, $item, $order ) {
        foreach ( $order->get_items() as $order_item_id => $order_item_data ) {
            if ( $order_item_id == $item_id ) {
    
    
                $order_item_data->set_subtotal('20.22');
                $order_item_data->set_total(20.22);
                $order->apply_changes();
                $order->save();
    				
    		}
        }
    }
     
  • 5 years-11 months

    How to change user role after wordpress registration

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

    This action hook allows you to access data for a new user immediately after they are added to the database. The user id is passed to hook as an argument.

    add_action( 'user_register', 'eddpremium_register_fields_save');
    add_action( 'profile_update', 'eddpremium_register_fields_save');
    
    function eddpremium_register_fields_save($user_id) {
    	$u = new WP_User($user_id);
    
    	// Remove role
    	$u->remove_role( 'subscriber' );
    
    	// Add role
    	$u->add_role( 'author' );
    }
     
  • 5 years-11 months

    how to add custom menu code in wordpress templates

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

    If you want to add custom navigation menus in your WordPress templates? By default, many WordPress themes come with pre-defined menu locations and layouts. follow this article:

    <?php $defaults = array(
        'menu'            => 'main',
        'container'       => 'div',
        'container_class' => 'navbar-collapse collapse',
        'container_id' => 'navbar',
        'menu_class'      => 'nav navbar-nav navbar-right',
        'echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>'
    );
    ?>
     
    <?php wp_nav_menu( $defaults ); ?>
    
    /* Output */
    
    <div id="navbar" class="navbar-collapse collapse">
    	<ul id="menu-main" class="nav navbar-nav navbar-right">
    		<li id="menu-item-108" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-home current-menu-item page_item page-item-2 current_page_item menu-item-108"><a href="http://www.example.com/">Home</a></li>
    	</ul>
    </div>
  • 5 years-11 months

    how to add a custom fields to wordpress pages and custom post type

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

    The hook allows meta box registration for any post type. Passes two parameters: $post_type and $post. Note: You can also use add_meta_boxes_{post_type} for best practice, so your hook will only run when editing a specific post type. This will only receive 1 parameter - $post.

    Add this to functions.php
    add_action( 'add_meta_boxes', 'gp_add_meta_boxes' );
    function gp_add_meta_boxes() {
        add_meta_box( 'gp_product', 'Products Options', 'gp_products_callback', 'review', 'normal', 'high' );
    }
    
    function gp_products_callback( $post ) {
        $fname = get_post_meta( $post->ID, 'fname', true );
    
    // reset choices
    	$field['choices'] = array();
    	
    	$users = get_users();
    	?>
    	<select name="cust_user"></select>
    	<?php
    	foreach ($users as $user) {
    		$field[ $user->ID ] = $user->display_name;
    	}
    
        ?>
        <p>First Name: <input type="text" name="fname" value="<?php echo $fname; ?>"></p>
        <?php
    }
     
  • 3 years-4 months

    Page Hits Using Php

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

    Website visitor using php.

    $datei = fopen(APPPATH."/cache/countlog.txt","r");
    $count = fgets($datei,1000);
    fclose($datei);
    $count=$count +  1 ;
    echo "$count" ;
    // opens countlog.txt to change new hit number
    $datei = fopen(APPPATH."/cache/countlog.txt","w");
    fwrite($datei, $count);
    fclose($datei);
  • 5 years-11 months

    How to WooCommerce state field (billing or shipping) not required on checkout page

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

    Try this code in your functions.php file

    add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 10, 1 );
    add_filter( 'woocommerce_shipping_fields', 'woo_filter_state_shipping', 10, 1 );
    function woo_filter_state_billing( $address_fields ) { 
      $address_fields['billing_state']['required'] = false;
    	return $address_fields;
    }
    function woo_filter_state_shipping( $address_fields ) { 
    	$address_fields['shipping_state']['required'] = false;
    	return $address_fields;
    }
     
  • 5 years-11 months

    How to Update PHP cookie or Update if not set and get cookie all values using codeigniter

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

    A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is a small piece of data sent from a website and stored in a user's web browser while the user is browsing that website. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

    Note: The setcookie() function must appear BEFORE the <html> tag.
    public function add_cookies($name,$value="",$time=3600) {
    	$this->load->helper('cookie');
    	if($value=="") {
    		return json_decode(get_cookie($name),true);
    	}
    	$val=$value;
    	if($val!="") {
    		$search1=get_cookie($name);
    		if($search1!="") {
    			$search1=json_decode($search1,true);
    			if(!in_array($val, $search1)) {
    				$search1[]=$val;
    				$cookie= array(
    				       'name'   => $name,
    				       'value'  => json_encode($search1),
    				       'expire' => $time,
    				   );
    				set_cookie($cookie);
    			}
    		} else {
    			$value=array();
    			$value[]=$val;
    			$cookie= array(
    			       'name'   => $name,
    			       'value'  => json_encode($value),
    			       'expire' => $time,
    			   );
    			set_cookie($cookie);
    		}
    	}
    	return json_decode(get_cookie($name),true);
    }
     
  • 5 years-11 months

    How to Connect with MySQLi or PDO Server through PHP

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

    PHP you can easily do this using the mysqli_connect() function. All communication between PHP and the MySQL database server takes place through this connection. The basic syntaxes for connecting to MySQL using MySQLi and PDO extensions:

    Syntax: MySQLi, Procedural way
    $con = mysqli_connect("hostname", "username", "password", "database");
    Syntax: MySQLi, Object Oriented way
    $con = new mysqli("hostname", "username", "password", "database");
    Syntax: PHP Data Objects (PDO) way
    $pdo = new PDO("mysql:host=hostname;dbname=database", "username", "password"); 
    Example (mysqli)

    Perform queries against the database:
    <?php
    $con=mysqli_connect("localhost","your_user","your_password","your_db");
    // Check connection
    if(mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    // Perform queries
    mysqli_query($con,"SELECT * FROM yourtable");
    mysqli_query($con,"INSERT INTO yourtable (FName,LName,Age)
    VALUES ('Glen','Quagmir',65)");
    
    mysqli_close($con);
    ?> 
    Example (PDO)

    Perform queries against the database:
    <?php
    $servername = "localhost";
    $username = "your_username";
    $password = "your_password";
    $dbname = "your_DBPDO";
    
    try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        // set the PDO error mode to exception
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
        // prepare sql and bind parameters
        $stmt = $conn->prepare("INSERT INTO yourGuests (ftname, lname, email)
        VALUES (:ftname, :lname, :email)");
        $stmt->bindParam(':ftname', $firstname);
        $stmt->bindParam(':lname', $lastname);
        $stmt->bindParam(':email', $email);
    
        // insert a row
        $firstname = "John";
        $lastname = "Doe";
        $email = "john@domain.com";
        $stmt->execute();
    
        // insert another row
        $firstname = "Julie1";
        $lastname = "Dooley1";
        $email = "julie1@domain.com";
        $stmt->execute();
    
        echo "New records added successfully";
        }
    catch(PDOException $e)
    {
    echo "Error: " . $e->getMessage();
    }
    $conn = null;
    ?> 
     
  • 5 years-11 months

    Anybody know that how to create HTML to PDF in PHP with phpToPDF

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

    Now generate 'A5' sized PDF from html and display it view. The PDF name will be 'simple_any_name.pdf'.

    <?php
     // INCLUDE THE phpToPDF.php FILE
    require("phpToPDF.php"); 
    
    // PUT YOUR HTML IN A VARIABLE
    $my_html="<HTML>
    <h2>Test HTML 02</h2><br><br>
    <div style=\"display:block; padding:20px; border:2pt solid:#FE9A2E; background-color:#F6E3CE; font-weight:bold;\">
    phpToPDF is pretty cool! <br><br>
    [This was orange, but I set the PDF option to monochrome (Black & White)]
    </div><br><br>
    For more examples, visit us here --> https://www.dorcode.com/
    </HTML>";
    
    // SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
    $pdf_options = array(
      "source_type" => 'html',
      "source" => $my_html,
      "action" => 'view',
      "color" => 'monochrome',
      "page_orientation" => 'landscape',
      "file_name" => 'simple_any_name.pdf');
    
    // CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
    phptopdf($pdf_options);
    
    ?> 
     
  • Word cloud with jquery

    • Category : wordpress
    • Location : Unknown
    • Posted On :
    • Posted by : Harman1514965387

    How to create Word cloud with jquery

    How to create Jquery Word cloud with custom shapes .Like wordart.com.