Friday, June 21, 2013

Show cart contents / total at WooCommerce header in Wordpress?

Add the following bit of code to your header file exactly where you want to display the cart total items value.

<?php global $woocommerce; ?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?>
</a>

<!---Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)---->

<?php
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>

<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?>
</a>

<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
?>

Keep Smiling.
Naresh.

Thursday, June 20, 2013

How to add WooCommerce short codes in Wordpress Template files?

By using do_shortcode() function we can add the WooCommerce shortcode 
to the template files.
Syntax:
<?php echo do_shortcode( 'ShortCode' ); ?>
Example:
<?php echo do_shortcode( '[fblike]' ); ?>


Keep Smiling

Naresh.

How to display welcome note in Wordpress along with user name?

The following piece of code full fill your requirement.

<?php
global $current_user;
get_currentuserinfo();
if(isset($current_user->user_login))
{
    $name=$current_user->user_login;
    echo 'Welcome '.ucfirst($name);
}
else
{

}
?>

......................
Keep Smilimg.

Thursday, May 2, 2013

How to create dynamic select boxes in Codeigniter form using AJAX?

The follownig code clearly explains you how to dynamic select boxes usin AJAX in codeigniter.

VIEW:

<div class="slidtxt">Category :</div>
<div class="slidfield">
<select name="category" id="sc_get">
<option value="ap">Andhrapradesh</option>
<option value="tn">Tamilnadu</option>
<option value="kr">Karnataka</option>
<option value="kl">Kerala</option>
</select>
</div>

<div class="slidtxt">Sub Category :</div>
<div class="slidfield">
<select name="subcat" id="sc_show">

</select>
</div>

<script>
//Script for getting the dynamic values from database using jQuery and AJAX
$(document).ready(function() {
    $('#sc_get').change(function() {

var form_data = {
name: $('#sc_get').val()
};

$.ajax({
url: "<?php echo site_url('controller_name/method'); ?>",
type: 'POST',
dataType: 'json',
data: form_data,
success: function(msg) {
var sc='';
$.each(msg, function(key, val) {
sc+='<option value="'+val.sub_cat+'">'+val.sub_cat+'</option>';
});
$("#sc_show option").remove();
$("#sc_show").append(sc);
}
});
});
});
</script>




CONTROLLER:

public function get_subcat()
{
        $cat=$this->input->post('name');
        $table='subcat';
        $where=array('cat' => $cat);
        $data['sc_get']=$this->admin->get_where_data($table,$where);
        $sc=json_encode($data['sc_get']);
        echo $sc;
}


MODEL:

public function get_where_data($table,$where)
{
        $query=$this->db->get_where($table,$where);
        return $query->result_array();
}





...........................
Have a Great Day.
Keep Smiling....




Friday, April 5, 2013

How to raplace one page to another address ?

 By using the following Javascript we can redirect from current page to another address.
<script>
window.onbeforeunload = function () {
   location.replace('http://www.google.com');
   return "This session is expired and the history altered.";
}
</script>
Note: Placed in header is preferable one. 

Tuesday, April 2, 2013

In PHP, how to search a value existed or not in array?

By using in_array function we can knows the element existed or not in that array.

Syntax:

         in_array('search_array_value',$search_array);

Example:

$fruits=array('Apple','Bananna','grapes','Mango');  

In the above array fruits we want to know the array having 'Bananna' value or not!

 if (in_array('Bananna',$fruits))
        {
                   echo 'Fruits having Bananna';
        }
        else
        {
                  echo 'Fruits doesn't having Bananna';
        }

Monday, April 1, 2013

How to add confirmation box to forms using Javascript?

No need to worry, it's a simple task. By adding "onclick" function to submit buttons.
syntax:  
onclick="return confirm('Do you like to proceed?');"
Example: 
<input type="submit" name="submit" value="Submit" onclick="return confirm('Do you like to proceed?');">