Posts

Add minimum charge in Woocommerce cart page

// Paste below code in your active theme s functions.php add_action( 'woocommerce_cart_calculate_fees', ' wc_add_minimum_fee ' ); function wc_add_minimum_fee (){ global $woocommerce; $stotal = $woocommerce->cart->subtotal; if ($ stotal < 999 ) { $surcharge = 100; } else { $surcharge = 0; } $woocommerce->cart->add_fee( __('Surcharge', 'woocommerce'), $surcharge ); }

Login with email or username in codeigniter

function login_user() { $email= $this->input->post('email'); $password= MD5($this->input->post('password')); $this->db->where("(Email='$email' OR Username='$email') AND Password='$password' "); $Query = $this->db->get('users'); if($Query->num_rows() > 0) { return $Query->row(); } else { return false; } }

Convert JSON string to Array in php

$json_string = '{ "title": "PHP: The Definitive Guide", "author": "Arun Verma", }' ; $res = json_decode ( $json , true ) ; echo $res [ 'title' ] ; // PHP: The Definitive Guide

Install XAMPP 1.8.3-4 on Ubuntu 32 bit

Step 1: Paste below code to ubuntu terminal to Download the installer.             wget http://downloads.sourceforge.net/project/xampp/XAMPP%20Linux/1.8.3/xampp-linux-1.8.3-4-installer.run Step 2: Run the installer             sudo chmod +x xampp-linux-1.8.3-4-installer.run           sudo ./xampp-linux-1.8.3-4-installer.run Step 3: Follow the xampp installation setup screen

Remove last comma from string in php

$string = "Bar, Restaurant, Take Away Food, Dive School, Hotel,"; rtrim($string, ","); or   You can use substr( $string, 0, -1);

Add http before url in php

function addhttp ( $url ) { if (! preg_match ( "~^(?:f|ht)tps?://~i" , $url )) { $url = "http://" . $url ; } return $url ; }

Reverse an array in php without using the reverse function

<?php $array = array(1, 2, 3, 4); $size = sizeof($array); for($i=$size-1; $i>=0; $i--){ echo $array[$i]; } ?>