Do something after WooCommerce order completed

If you want to do something after WooCommerce order completed you can hook into woocommerce_order_status_completed.

add_action( 'woocommerce_order_status_completed', 'my_function' );
 * Do something after WooCommerce sets an order on completed
function my_function($order_id) {
	// order object (optional but handy)
	$order = new WC_Order( $order_id );
	// do some stuff here

Have any doubt, then comment here!

Get category ID by using category name in wordpress

If you want to get category id by using category name then use the following code

function get_category_id($cat_name){
	$term = get_term_by('name', $cat_name, 'category');
	return $term->term_id;

then Just call the function with your category name as a parameter. for example

$category_ID = get_category_id('Books');

Now you can get the category Id in variable $category_ID.

Have any doubt, then comment here!

create an autocomplete textbox in wordpress

Just add a div under the input tag

HTML Code:

<input type="text" id="city" name="city" autocomplete="off"/> 
<div id="key"></div>

replace the div after the success on you ajax.

Ajax Code:

     var ajaxurl="<?php echo admin_url( 'admin-ajax.php' ); ?>"; 
     var data ={ action: "city_action",  city:cid    };
        $.post(ajaxurl, data, function (response){

PHP Code:

       function city_action_callback() {     
       global $wpdb;
            $result =   $mytables=$wpdb->get_results("select * from ".$wpdb->prefix . "mycity where city like '%".$city."'" );   
            $data = "";
            echo '<ul>'
            foreach($result as $dis)
                         echo '<li>'.$dis->city.'</li>';
            echo '</ul>'    

Have any doubt, then comment here!

Get All Images From WordPress Media Gallery

Uploaded images are stored as posts with the type “attachment”. Use get_posts() and query for all attachments:

$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' =>'image',
'post_status' => 'inherit',
'post_parent' => null, // any parent
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
the_attachment_link($post->ID, false);

Now All images are displayed.

Have any doubt, then comment here!