Constructor in PHP

Sunday, 22 November 2026

A special function in class. Calls automatically when an object is created. __construct (two underscores) is fixed name for constructor. In PHP you can create only 1 constructor for each class.

class ConstructorDemo{
    function __construct(){
        echo "constructor called";
    }
}

$cd = new ConstructorDemo();

Output:

constructor called

Constructor is used for default values, database connections, etc.

Properties Declaration in PHP

In class variables are called Properties. Properties start with public keyword. Without public keyword you get error.

class Maths{
    public $value;
    //property declared
    public $value2 = 100;
}

Property usage in methods:

Functions inside class are called Methods. This is how properties are used in methods.

class Maths{
    //property declared but value is not assigned
    public $value;
    public $a = 0;
    //method declaration
    function sum($v){ 
        //property value assigned
        $this->value = 10;
        return $this->value + 10 + $v;
    }
}

$Obj = new Maths();
//calling method inside class, zero is function parameter
echo $Obj->sum(0); 
echo "
"; //calling public property that is inside class echo $Obj->a;

Output:

20
0

PHP OOPS Object Declaration

Any number of objects can be created from single class. Remember to add new keyword before class name and close with round braces. Object declaration comes outside class.

$obj = new Maths();
$obj2 = new Maths();
$cd = new Demo; // this is also correct for creating object

PHP Class Declaration

In class name declaration starting letter must be capital. Remember to add curly braces.

class Maths{

}

WordPress Free Plugin That Supports PayPal, Stripe, Constant Contact

Sunday, 6 April 2025

 WPForms Lite free WordPress plugin supports PayPal, Stripe, and Constant Contact.

https://wordpress.org/plugins/wpforms-lite/

How to add custom discounts to the WooCommerce checkout page WordPress

Saturday, 5 April 2025

Original article is found here
/**
 * @snippet       Dynamic Fee @ WooCommerce Checkout
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 3.9
 * @community     https://businessbloomer.com/club/
 * 
 */
 
// Part 1 
// Display Radio Buttons
  
add_action( 'woocommerce_review_order_before_payment', 'bbloomer_checkout_radio_choice' );
  
function bbloomer_checkout_radio_choice() {
     
   $chosen = WC()->session->get( 'radio_chosen' );
   $chosen = empty( $chosen ) ? WC()->checkout->get_value( 'radio_choice' ) : $chosen;
   $chosen = empty( $chosen ) ? '0' : $chosen;
        
   $args = array(
   'type' => 'radio',
   'class' => array( 'form-row-wide', 'update_totals_on_change' ),
   'options' => array(
      '0' => 'Pay Special Offer Amount ₹3000/-',
      '-1000' => 'Pre-booking Request for ₹2000/-',
      '-2000' => 'Pre-booking Request for ₹1000/-',
   ),
   'default' => $chosen
   );
     
   echo '<div id="checkout-radio">';
   echo '<h3 style="margin-bottom:15px;">Customize Your Order!</h3>';
   woocommerce_form_field( 'radio_choice', $args, $chosen );
   echo '</div>';
     
}
  
// Part 2 
// Add Fee and Calculate Total
   
add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_checkout_radio_choice_fee', 20, 1 );
  
function bbloomer_checkout_radio_choice_fee( $cart ) {
   
   if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
    
   $radio = WC()->session->get( 'radio_chosen' );
     
   if ( $radio ) {
      $cart->add_fee( 'Discounted Price', $radio );
   }
   
}
  
// Part 3 
// Add Radio Choice to Session
  
add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_checkout_radio_choice_set_session' );
  
function bbloomer_checkout_radio_choice_set_session( $posted_data ) {
    parse_str( $posted_data, $output );
    if ( isset( $output['radio_choice'] ) ){
        WC()->session->set( 'radio_chosen', $output['radio_choice'] );
    }
}

Get a maximum of 750 or 7% off whichever is lower on any purchase on Ebay India

Tuesday, 11 August 2015

I bought Internet pack on Vodafone website they gave me this gift voucher of eBay India after completing the transaction with that website. I don't want this voucher, so you can use it if you like. I am providing the details below.

eBay India Gift Voucher Code is :  NA4GCUDBYU

Gift Voucher Validity : Jan 1, 2015 - Sep 30, 2015

Visit www.ebay.in to redeem this eCoupon.