Skip to main content

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...

Magento add and update customer account by programmatically


$email = $customersdata['EmailAddress'];



if(!empty($email)):

$customerModel = Mage::getModel("customer/customer");
$customerModel->setWebsiteId($websiteId);
$customerModel->loadByEmail($email);

$customerModel = $customerModel->getData();


if(empty($customerModel)){

//echo '<pre>'; print_r($customerModel->getData()); exit;

$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId($websiteId)
            ->setStore($store)
            ->setGroupId($customersdata['PriceList'])
            ->setFirstname($fname)
            ->setLastname($lname)
            ->setSapcustomerid($customersdata['Code'])
            ->setCreditlimit($customersdata['CreditLimit'])
            ->setBalance($customersdata['Balance'])
            ->setRefcode($customersdata['RefCode'])
            ->setEmail($customersdata['EmailAddress'])
            ->setPassword('trinature2014');
 

try{
    $customer->save();
}
catch (Exception $e) {
    Zend_Debug::dump($e->getMessage());
}


/// is_default_billing
$params_b = array(
'firstname' => $fname,
'lastname' => $lname,
'street' => array($customersdata['BillTo_Street']),
'city' => $customersdata['BillTo_City'],
'country_id' => $customersdata['BillTo_Country'],
'region' => $customersdata['BillTo_State'],
'region_id' => 0,
'postcode' => $customersdata['BillTo_ZipCode'],
'telephone' => ($customersdata['Phone1'] != '' ? $customersdata['Phone1'] : ($customersdata['Phone2'] != '' ? $customersdata['Phone2'] : '0')),
'fax' => $customersdata['Fax'],
'is_default_billing' => true,
'is_default_shipping' => false
);
 //Add Customer Address
 $address   = Mage::getModel('customer/address');
  $customer->loadByEmail($email);
 $address->addData($params_b);
 $customer->addAddress($address);

   try{
       $customer->save();
    }
catch (Exception $e) {
    Zend_Debug::dump($e->getMessage());
}

//is_default_shipping
$params_s = array(
    'firstname' => $fname,
'lastname' => $lname,
'street' => array($customersdata['ShipTo_Street']),
'city' => $customersdata['ShipTo_City'],
'country_id' => $customersdata['ShipTo_Country'],
'region_id' => 0,
'postcode' => $customersdata['ShipTo_ZipCode'],
'telephone' => ($customersdata['Phone2'] != '' ? $customersdata['Phone2'] : ($customersdata['Phone1'] != '' ? $customersdata['Phone1'] : '0')),
'fax' => $customersdata['Fax'],
'is_default_billing' => false,
'is_default_shipping' => true
);
       
 //Add Customer Address
 $address   = Mage::getModel('customer/address');
  $customer->loadByEmail($email);
 $address->addData($params_s);
 $customer->addAddress($address);

   try{
       $customer->save();
    }
catch (Exception $e) {
    Zend_Debug::dump($e->getMessage());
}



/*

   $address = Mage::getModel("customer/address")
              ->setCustomerId($customer->getId())
              ->setFirstname($customer->getFirstname())
              ->setLastname($customer->getLastname())
              ->setCountryId($customersdata['BillTo_Country'])
              ->setRegion($customersdata['BillTo_State'])
              ->setPostcode($customersdata['BillTo_ZipCode'])
              ->setCity($customersdata['BillTo_City'])
              ->setTelephone($customersdata['Phone1'])
              ->setFax($customersdata['Fax'])
              ->setStreet($customersdata['ShipTo_Street'])
              ->setIsDefaultBilling('1')
              ->setIsDefaultShipping('1')
              ->setSaveInAddressBook('1');

             


   try{
       $address->save();
    }
catch (Exception $e) {
    Zend_Debug::dump($e->getMessage());
}
*/

// if we found the customer
if ($customer->getId() && $customersdata['Newsletter']=='Y'){
// load up the subscriber if possible
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customersdata['EmailAddress']);

    if (!$subscriber->getId()
|| $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED
        || $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
           
        $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
           $subscriber->setSubscriberEmail($email);
        $subscriber->setSubscriberConfirmCode($subscriber->RandomSequence());
    }

    $subscriber->setStoreId(Mage::app()->getStore()->getId());
    $subscriber->setCustomerId($customer->getId());
       
    try {
        $subscriber->save();
    }
    catch (Exception $e) {
        throw new Exception($e->getMessage());
    }
}

         
} // end if
else
{
   

if($customerModel)
{
   

$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
//load customer by email id //use

   
   Mage::log($email, null, 'nchile prod -'.$email.'.log');
         /*Load the customer addresses by Customer Id*/
        $customerAddressCollection = Mage::getResourceModel('customer/address_collection')->addAttributeToFilter('parent_id',$customer->getId())->getItems();
        foreach($customerAddressCollection as $customerAddress){
         $customer_address_id = $customerAddress->getData('entity_id');
            if($customer_address_id!=""){  
      /*Load the Customer Address by ID and delete it*/  
               Mage::getModel('customer/address')->load($customer_address_id)->delete();
            }
        }
       
sleep(1);
$customerData =  array (
                 
                    "firstname" => $fname,
                    "lastname" =>$lname,
                    "group_id" => $customersdata['PriceList'],
                    "creditlimit" => $customersdata['CreditLimit'],
                    "balance" => $customersdata['Balance'],
                    "refcode" => $customersdata['RefCode'],
                   
                );
               



$addressData =  array (
                 
                    'firstname' => $fname,
                    'lastname' => $lname,
                    'street' => array($customersdata['BillTo_Street']),
                    'city' => $customersdata['BillTo_City'],
                    'country_id' => $customersdata['BillTo_Country'],
                    'region' => $customersdata['BillTo_State'],
                    'region_id' => 0,
                    'postcode' => $customersdata['BillTo_ZipCode'],
                    'telephone' => ($customersdata['Phone1'] != '' ? $customersdata['Phone1'] : ($customersdata['Phone2'] != '' ? $customersdata['Phone2'] : '0')),
                    'fax' => $customersdata['Fax'],
                    "is_default_billing" => 1,
                    "is_default_shipping" => 0,
                );

 

 $addressData1 =  array (
                    'firstname' => $fname,
                    'lastname' => $lname,
                    'street' => array($customersdata['ShipTo_Street']),
                    'city' => $customersdata['ShipTo_City'],
                    'country_id' => $customersdata['ShipTo_Country'],
                    'region_id' => 0,
                    'postcode' => $customersdata['ShipTo_ZipCode'],
                    'telephone' => ($customersdata['Phone2'] != '' ? $customersdata['Phone2'] : ($customersdata['Phone1'] != '' ? $customersdata['Phone1'] : '0')),
                    'fax' => $customersdata['Fax'],
                    "is_default_billing" => 0,
                    "is_default_shipping" => 1,
                );
               
   
   

   
   
   
               
               
 $customer = Mage::getModel('customer/customer');
 $customer->loadByEmail($email);
//Add Customer Data
 $customer->addData($customerData);
 $customer->save();




 //Add Customer Address
 $address   = Mage::getModel('customer/address');
  $customer->loadByEmail($email);
 $address->addData($addressData);
 $customer->addAddress($address);

 $customer->save();






 //Add Customer Address
 $address   = Mage::getModel('customer/address');
$customer->loadByEmail($email);
 $address->addData($addressData1);
 $customer->addAddress($address);

 $customer->save();



}
   
   
}
$i++;
endif;
endif;
} //end foreach
} //end function

Comments

Post a Comment

Popular posts from this blog

Create Signature pad with save on database in php

Create Signature pad with save on database in php 1.create a folder images index.php ============   <!DOCTYPE >     <head>     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />     <title>Signature Pad</title>     <script type="text/javascript" src="jquery-1.8.0.min.js"></script>     <script type="text/javascript"> $(document).ready(function () {     /** Set Canvas Size **/     var canvasWidth = 400;     var canvasHeight = 100;     /** IE SUPPORT **/     var canvasDiv = document.getElementById('signaturePad');     canvas = document.createElement('canvas');     canvas.setAttribute('width', canvasWidth);     canvas.setAttribute('height', canvasHeight);     canvas.setAttribute('id', 'canvas');     canvasDiv.appendChild(canvas);    ...

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...

WooCommerce Mini cart With Ajax

WooCommerce Mini cart //MINI CART SECTION   <div class="productdiv rightcart">                                                         <?php if ( ! WC()->cart->is_empty() ) : ?>     <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">         <?php             do_action( 'woocommerce_before_mini_cart_contents' );             foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {                 $_product     = apply_filters( 'woocommerce_cart_item_pro...