Add Extra Charges In Woocommerce Cart

If you want to apply extra fee in the cart then Woocommerce provide an action for applying a fee on the cart.

The fee can be used as shipping fee, installation fee or whatever as per your requirement.

add_action( ‘woocommerce_cart_calculate_fees’, ‘add_extra_cart_fee’ ,10,1 );
This action calculates the total fee and adds into the cart amount.

This Woocommerce function is used to add the fee to Woocommerce cart.

How to use it ?

add_action( ‘woocommerce_cart_calculate_fees’, ‘add_extra_cart_fee’ ,10,1 );
function add_extra_cart_fee( $cart_object ) {

global $woocommerce;
$spfee = 14.00; // initialize special fee
$woocommerce-&gt;cart-&gt;add_fee( ‘Extra Tax Fee’, $spfee, true, ‘standard’ );




Implement Parent/Child Theme in Magento

At some point you will need to modify the code of the theme to customize a particular page to your needs. On Magento this is easily done by creating a child theme and modifying its files instead. This will protect the changes from being overwritten when you upgrade Magento or Intenso theme to a new version.

Like other popular CMS systems, Magento is based on a fall-back hierarchy, which means that if you have set a custom child theme, Magento will use the files of your child theme, and if it doesn’t find some of the necessary files it will use the ones from Intenso (and if the file is not present on Intenso it will use the Base default theme)

Instead of opening the template file and making modification to it, it is recommended to make a copy of that file and place it on your own child theme. In this article you will learn how to create a child theme and add to it the files you need to modify.

Magento consists of multiple template files, each one used to render a block of content in the frontend of the store. When you want to customize some section of a theme, you need to find first what is the name and route of the template file rendering that specific block. You can display the name of the template files of every block in the frontend by enabling Magento’s Template Path Hints.

To enable Magento’s Template Path Hints go to System > Configuration > Developer. Select your current website under Current Configuration Scope in the top left corner of the admin panel, and set Debug > Template Path Hints to Yes.

Now open the page you want to customize and find the path to the template. This way you can easily check which template files you need to edit to customize specific sections of Magento. Files that need to be modified can be copied to your custom sub-theme.

Child-Theme folder structure

The child-theme folder structure should be as follows:


In this case we named the folder “custom”, but you can use any name you like.

Once you have identified the right template to edit, you have to make a copy of the original file and paste it into your sub-theme directory. The directory structure inside the sub-theme must replicate the directory structure of the default theme.

When you’re creating a sub-theme in Magento you should only copy the files which you want to modify. Do not copy all files. Otherwise you will have tons of additional work in the future with any theme upgrade.

Activating the Child-Theme

You need to perform one additional step to let know Magento where to find your modified files. Just go to System > Configuration > Design, click the Themes tab and enter the name of your child-theme folder in the Default field.


Note: design changes made in System > Design overrides theme configurations made in System > Configuration > Design
Only use the System > Design menu to set seasonal design themes.

Hooks in Codeigniter

CodeIgniter  have gain lot of popularity for developing robust application as it  provides lots of rich features for rapid application development. One of the main feature we will discuss in this article is Hooks.

Hooks allows us to execute a script with specific path within the CodeIgniter execution process without modifying the core files of CodeIgniter

CodeIgniter follows the specific process but also allows the developer to  write their own code within that execution process. In simple language if you need to execute a code that should run every time after Constructor of a controller is loaded, you specify that script  (obviously a  function of a controller) path in hooks.

Hooks is basically a file located in following directory


There are different kind of hooks point which are distinguished by time when they are called in an execution process . The different types of hooks points  are as follows,

  • post_controller_constructor
  • pre_controller
  • pre_system
  • post_system
  • cache_override
  • display_override
  • post_controller

Initially when you download a fresh copy of CodeIgniter this file is empty except some comments specified. Basically the syntax to specify the hooks is as follows,

$hook[‘post_controller_constructor’] = array(
‘class’ => ‘App_auth’,
‘function’ => ‘index’,
‘filename’ => ‘App_auth.php’,
‘filepath’ => ‘controllers’,
‘params’ => ”

Let’s take an example of post_controller_constructor hook point with an example.Specifying  post_controller_constructor as a hook point means, calling the script  after the  contructor is  initiated, but before any function is called e.g. (user/userlist) etc.

As seen above we will write above code in a hook file. It means that callingindex() method of controller App_auth (located in application/controller folder) when any Class contructor is initiated. We can also specify parameters if required. Our App_auth controller will look as follows.

class Auth_auth
private $CI;

function Auth_auth()
$this->CI = &get_instance();

function index()
if ($this->CI->session->userdata(‘user_id’) == “” )  // If no session found redirect to login page.

Now, if user does any activity and if valid session is missing from system, user will be redirected to login page.

In this way we can use different hooks point for different purposes and write our own authentication code or a code which should compulsorily executed if  a specific action occurs in a system.

Note : Hooks feature should be enable in config file,
$config[‘enable_hooks’] = TRUE;


Remove index.php from url in Codeigniter using .htaccess


CodeIgniter is one of the best and popular php framework available today. Sometimes we need to remove the default index.php that appears in the url of codeigniter application, so that the url becomes more clean and SEO friendly. With the help of .htaccess file it’s very easy to do so.
Paste the following code into your .htaccess file which is on root folder of website, it will remove default index.php from the url:


RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]



Get Elapsed time(‘1 min ago’, ‘1 sec ago’, etc) from datetime

Many of the time we need to display the elapsed time from datetime field. This is mainly used in chatting system or in blog posting.

We can use the below function to get elapsed time:


function getTimeElapsedString($datetime, $full = false) {

$now = new DateTime(); // Current datetime $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array( 'y' => 'year', 'm' => 'month', 'w' => 'week', 'd' => 'day', 'h' => 'hour', 'i' => 'min', 's' => 'sec', ); foreach ($string as $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) { $string = array_slice($string, 0, 1); }

return $string ? implode(', ', $string) . ' ago' : 'just now';


we can call above function as

$string = getTimeElapsedString(‘2016-01-27 16:00:14’);

echo $string; // it will print 2 hours ago