Active Menu

Active Menu

Java Script

<script>
function selected(obj){
var lilist = document.getElementById(‘menu’);
var alist = lilist.getElementsByTagName(‘a’);
for (i=0; i<alist.length; i++ )
{
alist[i].className=””;
}
obj.className=”red”;
}
</script>

Style
<style>
.red {
color:red;
background:#F39;
width:150px;
}

HTML
<ul id=”menu”>
<li><a href=”#” onClick=”selected(this)”>Home</a></li>
<li><a href=”#”  onClick=”selected(this)”>About Us</a></li>
<li><a href=”#”  onClick=”selected(this)”>Our Products</a></li>
<li><a href=”#” onClick=”selected(this)”>Trade Offers</a></li>
<li><a href=”#”  onClick=”selected(this)”>Contact Us</a></li>
</ul>

0

WordPress Function

WordPress Function

  1. Jquery Include

    <?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>

2. Thumbnail Image

<?php the_post_thumbnail();?>

<?php  the_post_thumbnail(‘thumbnail’);  ?>

<?php  the_post_thumbnail(‘medium’);   ?>

<?php the_post_thumbnail(‘large’);      ?>

<?php the_post_thumbnail(‘full’);?>

    <?php the_post_thumbnail( array(100,100) );?>
3. Get Template Url 
    <?php get_template_directory(); ?> 
    <?php get_template_directory_uri(); ?>
0

How to Prevent Your WordPress Website from Being Hacked

How to Prevent Your WordPress Website from Being Hacked

  1. Keep your WordPress website updated with the latest version of WordPress.  Wordpress is regularly upgraded with new functionality and wity security measures that help stop hackers.
  2. Use complex usernames and passwords as described above.
  3. Install security plugins such as Better WP Security.  It covers most of the wordpress vulnerabilities mentioned earlier in this blog post.
  4. Install WP Security Scan.  It will scan your code and look for anything that is out of place like malware.  It will also make you aware of any vulnerabilities that it finds.
  5. Change the prefix of your WordPress database tables.
  6. Make the changes described earlier to your .htaccess file to prevent hackers from accessing important files that could cause vulnerabilities if accessed.  Also make changes to your .htaccess file to prevent SQL injection and URL hacks.
  7. Move your admin panel login to a URL that is not so easily identified and not common.  Limit the number of unsuccessful login attempts.
0

Woocommerce Category, Image , Description Display

<?php
$all_categories = get_categories( ‘taxonomy=product_cat&hide_empty=0&hierarchical=1’ );
foreach ($all_categories as $cat) {
//print_r($cat);
if($cat->category_parent == 13) {
$category_id = $cat->term_id;
$thumbnail_id     = get_woocommerce_term_meta( $cat->term_id, ‘thumbnail_id’, true );
$image = wp_get_attachment_url( $thumbnail_id );
/*echo ‘<a href=”‘. get_term_link($cat->slug, ‘product_cat’) .'”><div>’. “Read more” .'</div></a>’;*/

?>

<li style=”width: 183px;”>
<div>
<h3><?php  echo $cat->name; ?></h3>
<div><img src=”<?php echo $image; ?>” alt=”<?php $cat->name; ?>” width=”120″ height=”120″ /></div>
<p><?php echo $cat->description;?></p>

<?php echo ‘<a title=”Edit Product” href=”‘.get_term_link($cat->slug, ‘product_cat’).'”>Read More</a>’; ?>
</div>
</li>

<?php
}
}?>

0

How to change shipping rate in Percent

How to change shipping rate in Percent

app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php

find line

$method->setPrice($shippingPrice);

and put following code above that line

 

   $session        = Mage::getSingleton(‘checkout/session’);

            $quote_id       = $session->getQuoteId();

            $item_quote     = Mage::getModel(‘sales/quote’)->load($quote_id);

            $shippingPrice  = $item_quote->getSubtotal()*($this->getConfigData(‘price’)/100);

 

0

To Show Custom Option , configuration option , quantity in list page.

To Show Custom Option , configuration option , quantity in list page.

Put the code in place of where add to cart is now:

<?php echo $this->helper(‘checkout’)->formatPrice($_product->getFinalPrice()) ?>
<form action=”<?php echo Mage::getBaseUrl(); ?>checkout/cart/add/” method=”post” style=”display:block; clear:both;”>

<?php

$product = Mage::getModel(‘catalog/product’);
$product->load($_product->getId());

//print_r($product);
//exit();

$xml = “”;
$hasAtts = 0;

// configurable products
$productType = $product->getTypeId();

if($productType == “configurable”) {

// configurable products
$attValConfig = $product->getTypeInstance()->getConfigurableAttributesAsArray();

if(sizeof($attValConfig)) {

$hasAtts++;

foreach($attValConfig as $attValConfigSingle) {

$xml .= “<div class=’floatoption1′>”.$attValConfigSingle[‘frontend_label’].”: “;

$xml .= “<select style=’display:block; clear:both; margin-bottom:10px;’ name=’super_attribute[“.$attValConfigSingle[‘attribute_id’].”]’><option selected=’selected’>Choose an option</option>”;

foreach($attValConfigSingle[‘values’] as $attValConfigSingleVal) {

$baseprice = $this->getPriceHtml($product, true);
$strippedprice = str_replace(“£”, “”, $baseprice);
$numprice = strip_tags($strippedprice);
$numpricea = (float)$numprice;
$optionprice = $attValConfigSingleVal[‘pricing_value’];
$numpriceb = (float)$optionprice;
$catprice = $numpricea + $numpriceb;
$catpricea = number_format($catprice,2);

if (is_numeric($numpriceb)) {
$xml .= “<option value='”.$attValConfigSingleVal[‘value_index’].”‘>”.$attValConfigSingleVal[‘label’].” £”.$catpricea.”</option>”;
}   else { $xml .= “<option value='”.$attValConfigSingleVal[‘value_index’].”‘>Not Mumeric</option>”; }
}
$xml .= “</select></div>”;

}

}

}
// end configurable products

$attVal = $product->getOptions();

if(sizeof($attVal)) {

$hasAtts++;

foreach($attVal as $optionVal) {

$xml .= “<div class=’floatoption1′>Size:<select style=’display:block; clear:both; margin-bottom:10px;’ name=’options[“.$optionVal->getId().”]’><option selected=’selected’>Choose an option</option>”;

foreach($optionVal->getValues() as $valuesKey => $valuesVal) {
$xml .= “<option value='”.$valuesVal->getId().”‘>”.$valuesVal->getTitle().” +”.Mage::helper(‘core’)->currency($valuesVal->getPrice()).”</option>”;
}

$xml .= “</select></div>”;

}

}

$xml .= “<div class=’floatoption2′>Qty: <input style=’display:block; clear:both; margin-bottom:20px;’ id=’qty’ class=’input-text qty’ type=’text’ value=’1′ maxlength=’12’ name=’qty’/></div>”;

echo($xml);

?>

<input type=”hidden” name=”product” value=”<?php echo($_product->getId()); ?>” />
<div>
<button type=”submit”><span><span><?php echo $this->__(‘Add to Cart’) ?></span></span></button></div>

</form>
<script type=”text/javascript”>
var productAddToCartForm_<?php echo $_product->getId(); ?> = new VarienForm(‘product_addtocart_form_<?php echo $_product->getId(); ?>’);
productAddToCartForm_<?php echo $_product->getId(); ?>.submit = function(){
if (this.validator.validate()) {
this.form.submit();
}
}.bind(productAddToCartForm_<?php echo $_product->getId(); ?>);
</script>

0

Making default of product attributes like is_active,tax class, weight,status,stock,qty in magento

UPDATE `eav_attribute` SET `default_value` = ‘container1′ WHERE `eav_attribute`.`attribute_code`=’options_container’;
UPDATE `eav_attribute` SET `default_value` = ‘1’ WHERE `eav_attribute`.`attribute_code`=’is_active’;
UPDATE `eav_attribute` SET `default_value` = ‘1’ WHERE `eav_attribute`.`attribute_code`=’is_anchor’;
UPDATE `eav_attribute` SET `default_value` = ‘1’ WHERE `eav_attribute`.`attribute_code`=’status’;
UPDATE `eav_attribute` SET `default_value` = ‘0’ WHERE `eav_attribute`.`attribute_code`=’weight’;
UPDATE `eav_attribute` SET `default_value` = ‘2’ WHERE `eav_attribute`.`attribute_code`=’tax_class_id’;
insert into core_config_data values ( null, ‘default’, 0, ‘cataloginventory/item_options/is_in_stock’, 1 );
insert into core_config_data values ( null, ‘default’, 0, ‘cataloginventory/item_options/qty’, 10 );
Pre-populate the incremented new SKU to the SKU field by JavaScript.

0

Auto generated SKU when add product in magento

Auto generated SKU when add product in magento

Open /app/design/adminhtml/default/default/template/catalog/product/edit.phtml and add the following code to the bottom of the file:

<?php
$dbread = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’);
$sql = $dbread->query(“SELECT * FROM catalog_product_entity ORDER BY created_at DESC LIMIT 1″);
$res = $sql->fetch();
?>
<script type=”text/javascript”>
if(document.getElementById(‘sku’).value == “”){
document.getElementById(‘sku’).value = <?php echo (int)$res[“sku”] + 1; ?>;
}
</script>

Note:Read the SKU (must be an integer) of the last added product.
Increment the SKU by 1.

0

How To Get Special Price in magento Product

How To Get Special Price in magento Product

<?php
Mage::app();
Mage::getSingleton(‘core/session’, array(
‘name’ => ‘frontend’
));
$_productCollection = Mage::getResourceModel(‘catalogsearch/advanced_collection’)-> addAttributeToSelect(Mage::getSingleton(‘catalog/config’)-> getProductAttributes())->addMinimalPrice()->setPageSize(1)->addStoreFilter();
Mage::getSingleton(‘catalog/product_status’)->addVisibleFilterToCollection ($_productCollection);
Mage::getSingleton(‘catalog/product_visibility’)->addVisibleInSearchFilterToCollection ($_productCollection);
$todayDate    = date(‘m/d/y’);
$tomorrow     = mktime(0, 0, 0, date(‘m’), date(‘d’) + 1, date(‘y’));
$tomorrowDate = date(‘m/d/y’, $tomorrow);
$_productCollection->addAttributeToFilter(‘special_from_date’, array(
‘date’ => true,
‘to’ => $todayDate
))->addAttributeToFilter(‘special_to_date’, array(
‘or’ => array(
0 => array(
‘date’ => true,
‘from’ => $tomorrowDate
),
1 => array(
‘is’ => new Zend_Db_Expr(‘null’)
)
)
), ‘left’)->addAttributeToSort(‘special_from_date’, ‘desc’);
?>
<?php
$i = 0;
if ($i++ % 3 == 0)
?>
<ul>
<?php
$x = 2;
?>
<?php
foreach ($_productCollection as $_product) {
if ($_product->getData(‘special_price’) != null) {
?>
<li>
<h2><?php
if ($locale == en_US) {
echo $this->__(‘Special Offers’);
} else if ($locale == el_GR) {
echo $this->__(‘Προσφορές’);
} else {
echo $this->__(‘Special Offers’);
}
?></h2>

<img src=”<?php
echo $this->helper(‘catalog/image’)->init($_product, ‘thumbnail’)->resize(135);
?>” alt=”<?php
echo $_product->getName();
?>” width=”135″ height=”135″ />
<?php
$specialPrice = $_product->getData(‘special_price’);
$orignalPrice = $_product->getData(‘price’);
?>

<?php
}
}
?>

0

Custom Menu In Magento

Custom Menu In Magento

<?php

        $root_category = Mage::getModel(‘catalog/category’)->load(3); // Put your root category ID here.

        $subcategories = $root_category->getChildren();

  foreach(explode(‘,’,$subcategories) as $subcategory) {

        $category = Mage::getModel(‘catalog/category’)->load($subcategory);

        echo ‘<a href=”‘.$category->getURL() .'” />’.$category->getName().'</a><br/>’;

  }

  ?>

0