Fix: WordPress Memory Exhausted Error – Increase PHP Memory

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 30720 bytes)

You need to paste this code in wp-config.php file just before the line that says ‘That’s all, stop editing! Happy blogging.

define( 'WP_MEMORY_LIMIT', '256M' );

Woocommerce Snippets



|| Related products
   plugins > woocommerce > templates > single-product > related.php

|| how to move best seller product on the top
   go to storefront-template-hooks.php
   add_action( 'homepage', 'storefront_best_selling_products', 70 ); 
   add_action( 'homepage', 'storefront_best_selling_products', 10 );

|| img src directory
   <img src="<?php echo get_template_directory_uri(); ?>/assets/images/bd.jpg" width="" height="" alt="" />

|| custom css add
   <link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(). '/assets/css/custom.css' ?>">

|| Add Custom Fonts, top of the style.css file
   @font-face {
	font-family: calib;
	src: url('assets/fonts/calibrib.ttf');

|| search form anywhere
   <form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/'  ) ); ?>">
	<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
	<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />
	<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
	<input type="hidden" name="post_type" value="product" />

|| Number of related products
   add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' );
   function jk_related_products_args( $args ) {
	$args['posts_per_page'] = 4; // 4 related products
	$args['columns'] = 3; // arranged in 3 columns
	return $args;

|| How to Remove Product Review,  go to functions.php
   	add_filter( 'woocommerce_product_tabs', 'helloacm_remove_product_review', 99);
	function helloacm_remove_product_review($tabs) {
		return $tabs;

|| remove sidebar from product view page,  go to functions.php
   /* Storefront Theme – Remove WooCommerce Sidebar on the Single Product Page */
	add_action( 'get_header', 'bbloomer_remove_storefront_sidebar' );
	function bbloomer_remove_storefront_sidebar() {
	    if ( is_product() ) {
	        remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );

|| add to cart text change, go to functions.php
   /* custom function add for add to cart text change */
	add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );    // 2.1 + 
	function woo_archive_custom_cart_button_text() {
	    return __( 'BY NOW', 'woocommerce' );

|| how to change product column
   your theme > inc > woocommerce > storefront-woocommerce-template-functions.php
   search storefront_loop_columns

|| How do I add WooCommerce product categories to a custom menu?
    Go to Appearance > Menus
    In the upper right corner, click on Screen Options and ensure the "Products" and "Product Categories" boxes are checked

|| Display My Account link in a template file
   <?php if ( is_user_logged_in() ) { ?>
      <a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
   <?php } 
   else { ?>
      <a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?</a>
   <?php } ?>

|| How to enable registration on "My Account" page
   Go to WooCommerce > Settings > Account and  Enable customer registration on the "My account" page.

|| How To Change Product Images Size?
   1st woocommerce > setting > product > Display > Product Images
   2nd Regenerate Thumbnails plugins install and active
   tutorial link:

|| product detail page sku and category

|| Product listing page product name
   <a href="<?php the_permalink(); ?>">---- </a>

|| product view page review tab remove

	add_filter( 'woocommerce_product_tabs', 'sb_woo_remove_reviews_tab', 98);
	function sb_woo_remove_reviews_tab($tabs) {


	 return $tabs;

|| product view short description:

|| breadcrumbs slash '/' replace as '>'

	add_filter( 'woocommerce_breadcrumb_defaults', 'my_change_breadcrumb_delimiter' );
	function my_change_breadcrumb_delimiter( $defaults ) {
	 // Change the breadcrumb delimiter from '/' to '>'
	 $defaults['delimiter'] = ' > ';
	 return $defaults;

|| Default breadcrumbs remove from product page:
   <?php remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);?>

|| prodcut view page related product remove
   <?php remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );?>

|| Add to cart remove:
		/* product listing page add to cart remove */
		function remove_loop_button(){
			remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
		remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
		/* product detail page add to cart remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

|| Price Remove
		/* product listing page price remove */
		remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
		/* product detail page price remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

|| edit products page:

You need to add a folder to your theme named "woocommerce" and copy the contents from the woocommerce plugin folder under "templates", 
copy archive-product.php and paste your theme woocommerce folder. The loop folder contains the files you want to use. 
so, in your theme, you'd have something like
	do_action( 'woocommerce_sidebar' )

|| Dynamic Product Category in sidebar:
   Appearance > Widget:
   drag and drop (WooCommerce Product Categories) in (primary sidebar) or (secondary widget area)

|| Dynamic product category anywhere:

	/* product category */
	function wooCommerceCategories() {

		$taxonomy     = 'product_cat';
		$orderby      = 'name';  
		$show_count   = 0;      // 1 for yes, 0 for no
		$pad_counts   = 0;      // 1 for yes, 0 for no
		$hierarchical = 1;      // 1 for yes, 0 for no  
		$title        = '';  
		$empty        = 0;

		$args = array(
			'taxonomy'     => $taxonomy,
			'orderby'      => $orderby,
			'show_count'   => $show_count,
			'pad_counts'   => $pad_counts,
			'hierarchical' => $hierarchical,
			'title_li'     => $title,
			'hide_empty'   => $empty
		$all_categories = get_categories( $args );
		 foreach ($all_categories as $cat) {
			if($cat->category_parent == 0) {
				$category_id = $cat->term_id;       
				echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>'; 
				$args2 = array(
						'taxonomy'     => $taxonomy,
						'child_of'     => 0,
						'parent'       => $category_id,
						'orderby'      => $orderby,
						'show_count'   => $show_count,
						'pad_counts'   => $pad_counts,
						'hierarchical' => $hierarchical,
						'title_li'     => $title,
						'hide_empty'   => $empty
				$sub_cats = get_categories( $args2 );
				if($sub_cats) {
					foreach($sub_cats as $sub_category) {
						echo  $sub_category->name ;

/* function call */

<div class="product_category col-lg-1 col-md-2">
     <?php if(function_exists("wooCommerceCategories")) wooCommerceCategories(); ?>

Google Live Map


Template Name: map


<script src=""></script>

	.common_page_container {border-top: 1px dashed #dddddd;margin:14px auto;padding: 24px 0;}
	.outletadd {padding: 0 0 0 3%;width:36%;}
	.store-col {float: left;margin: 0;}
	.store-col li {background:#f6f6f6;border: 1px solid #ddd;list-style: none;margin: 0 0 6px;padding: 3px 6px;}
	.store-col a {text-decoration: none; font-size: 13px;}
	#map-add {font-size: 13px; font-family: arial;} {float: left;margin: 0px;width:100%;}
	#MapCanvas {margin: 0;  max-width: 100%;min-height:380px;min-width: 300px;padding: 0;}

<script type="text/javascript">
	function updateMap(selectControl){ 
			case 'Shimanto': 
			  initialize(23.738143,90.376614, "1st Floor, Road no-2, Dhanmondi, Dhaka<br/>Phone:+8802-8618890");
			  addressChange("Shimanto Square: <br/> 1st Floor, Road no-2, Dhanmondi, Dhaka <br/>Mobile:+88-01730068075");
			case 'Mohammadpur':
			  initialize(23.76508,90.358429, "Shop No. 223-224, Toyko Square, Japan Garden City <br/>Mobile:+88-01730068069");
			  addressChange("Mohammadpur: <br/>Shop No. 223-224, Toyko Square, Japan Garden City <br/>Mobile:+88-01730068069");

	function initialize(lat,Lng,titletxt) { 
	    var mapOptions = {
	      center: new google.maps.LatLng(lat,Lng),
	      zoom: 17

	    var map = new google.maps.Map(document.getElementById("MapCanvas"),mapOptions);
		var marker = new google.maps.Marker({
			position: new google.maps.LatLng(lat,Lng),
			map: map,
			icon: ''
			//title: 'Rang'

		var infowindow = new google.maps.InfoWindow({
		  content: titletxt,
		  zIndex: 990,

	function addressChange(add){
		document.getElementById('map-add').innerHTML = add;	

	jQuery(document).ready( function($) {
		google.maps.event.addDomListener(window, 'load', initialize(24.1263456,90.3802059, "269-272 Tejgaon I/A Dhaka-1208, Bangladesh <br/>Tel: +88 02-8870616, 8870631<br/>"),check);	

<div class="common_page_container">
	<div class="selectoutlet store-col">
			<li><a href="javascript:;" rel="Shimanto" onclick="updateMap(this.rel)">&nbsp; Shimanto Square</a></li>
			<li><a href="javascript:;" rel="Mohammadpur" onclick="updateMap(this.rel)">&nbsp; Mohammadpur</a></li>
			<select name="mapchange"  onchange="updateMap(this.options[this.selectedIndex].value)">
				<option value="Basundhara">&nbsp; Basundhara City</option>
				<option value="pink_city">&nbsp; Pink City</option>
				<option value="jamuna_future">&nbsp;Jamuna Future Park 1</option>
				<option value="jamuna_future2">&nbsp;Jamuna Future Park 2</option>
		</form> -->
	<div class="outletadd store-col">
		<div id="map-add">269-272 Tejgaon I/A Dhaka-1208, Bangladesh <br/>Tel: +88 02-8870616, 8870631<br/>E-mail:</div>
	<div class="map-add store-col">
		<div id="MapCanvas"></div>
	<div class="clearer"></div>



How to display best selling products in magento

1. Create a new file for Block:

 * Catalog Product Bestseller Block
 * @author Amasty Team
class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract
    public function getCollection()
        $storeId = Mage::app()->getStore()->getId();
        $collection = Mage::getResourceModel('reports/product_collection')
            ->setOrder('ordered_qty', 'desc');
        if (Mage::helper('catalog/product_flat')->isEnabled()) {
                ->joinInner(array('e2' => 'catalog_product_flat_' . $storeId), 'e2.entity_id = e.entity_id');
        } else {
                ->addAttributeToSelect(array('name', 'price', 'small_image'));
        if ($categoryId = $this->getCategory()) {
            $category = Mage::getModel('catalog/category')->load($categoryId);
        $collection->setPage(1, $this->getLimit());
        return $collection;

2. Create a template file 

 * Bestseller Products block template
 * @see Mage_Catalog_Block_Product_Bestseller
<div class="block block-list block-viewed">
    <div class="block-title">
        <strong><span><?php echo $this->__($this->getHeader()) ?></span></strong>
    <div class="block-content">
        <?php $products = $this->getCollection(); ?>
        <?php if (0 < $products->getSize()) { ?>
            <table class="bestseller-table">
                    <?php foreach ($products as $p) { ?>
                        <td style="padding: 15px 15px 0px 15px;">
                            <a href="<?php echo $p->getProductUrl() ?>" title="<?php echo $this->htmlEscape($p->getName()) ?>" class="product-image">
                                <img src="<?php echo $this->helper('catalog/image')->init($p, 'small_image')->resize(125) ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($p->getName()) ?>" />
                            <h3 class="product-name">
                                <a href="<?php echo $p->getProductUrl() ?>" title="<?php echo $this->htmlEscape($p->getName())?>">
                                    <?php echo $this->htmlEscape($p->getName()) ?>
                            <?php echo $this->getPriceHtml($p, true) ?>
                    <?php } ?>
                    <?php foreach ($products as $p) { ?>
                    <td style="padding: 0px 15px 15px;">
                        <?php if($p->isSaleable()): ?>
                            <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($p) ?>')">
                                <span><span><?php echo $this->__('Add to Cart') ?></span></span>
                        <?php else: ?>
                            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                    <?php } ?>
        <?php } ?>

3. Now you need to call the created block, to do that go to Backend > CMS > Pages > Edit Page ‘Home page’ and add the following lines of code:

{{block type="catalog/product_bestseller" template="catalog/product/bestseller.phtml" header="Bestsellers" limit=4}}

4. You need to create a permission for this block:
   Backend – > System – > Permissions – > Blocks – > 'Add New Block' button

Create a storefront theme

Go to /app/design/frontend

1.Declare your theme

<?xml version="1.0" encoding="UTF-8"?>
<theme xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
     <title>My First Theme</title> <!-- your theme's name -->
     <parent>Magento/blank</parent> <!-- the parent theme, in case your theme inherits from an existing theme -->
         <preview_image>media/preview.jpg</preview_image> <!-- the path to your theme's preview image -->

2.Add registration.php

 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.

3.Configure images
Product image sizes and other properties used on the storefront are configured in a view.xml configuration file. For example, here is the view.xml of the Magento Blank theme: app/design/frontend/Magento/blank/etc/view.xml  copy that and past your view.xml file

4.Include CSS
include your CSS in default_head_blocks.xml of the Magento_Theme module, which defines the default <head> page section for all Magento pages.

<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <css src="css/styles-m.css" />
        <css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
        <css src="css/print.css" media="print" />
        <css src="css/custom.css" media="print"/>

Magento theme location

Storefront themes are conventionally located under app/design/frontend/<Vendor>/. Though technically they can reside in other directories. For example Magento built-in themes can be located under vendor/magento/theme-frontend-<theme_code> when a Magento instance is deployed from the Composer repository.

Resize catalog images

Generally, product images are cached while saving the product. However, the magento catalog:images:resize command enables you to resize all images for display on your storefront.

php bin/magento catalog:images:resize


Magento 2 Index Management

|| Magento2 reindex on local server

You can’t reindex from admin web. you have to reindex from command line

  1. go to command line from magento2 installation root directory

  2. php bin/magento indexer:reindex

if you got any error like ‘php’ is not recognized as an internal or external command,

so you need to Add E:\xampp\php to your PATH Environment Variable.

final command:
E:\xampp\htdocs\magento2>php bin/magento indexer:reindex

Image uploading Problem

|| File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini file

|| solved: Go to the file directory public_html wp-admin then put the php.ini file, and include following code

upload_max_filesize = 64M;
post_max_size = 32M;
safe_mode = off;

Image upload error

|| Magento 1.9.2 and php7 – image upload error:
check console: Uncaught Error: Function name must be a string in