Woocommerce Help code

/****************************/

Woocommerce:
===============

|| 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" />
   </form>


|| 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) {
		unset($tabs['reviews']);
		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: https://www.youtube.com/watch?v=YVLb3eG0JdI
   

|| product detail page sku and category
   wp-content\plugins\woocommerce\templates\single-product\meta.php

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

|| product view page review tab remove

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

	 unset($tabs['reviews']);

	 return $tabs;
	}
?>

|| product view short description:
   woocommerce/single-product/short-description.php

|| breadcrumbs slash '/' replace as '>'
   function.php

<?php
	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:
   function.php
   <?php remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);?>

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

|| Add to cart remove:
        <?php
		/* 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 );
		}
		add_action('init','remove_loop_button');
			or
		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
       <?php
		/* 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
themefolder/woocommerce/archive-product.php
themefolder/woocommerce/loop/...
<?php
	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:
   function.php

<?php
	/* 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(); ?>
</div>


Advertisements

Google Live Map

<?php

/*
Template Name: map
*/

get_header();

?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCPj2rrgRVKPap-cVS9_Wpd4fkBkXGF7fI&callback=myMap"></script>

<style>
	.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;}
	.map-add.store-col {float: left;margin: 0px;width:100%;}
	#MapCanvas {margin: 0;  max-width: 100%;min-height:380px;min-width: 300px;padding: 0;}
</style>

<script type="text/javascript">
	function updateMap(selectControl){ 
	    switch(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");
			  break; 
			  
			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");
			  break;
		}
	}   


	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: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
			//title: 'Rang'
		});

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

		infowindow.open(map,marker);
	}

	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);	
	});
		
</script>



<div class="common_page_container">
	<div class="selectoutlet store-col">
		<ul>
			<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>
			
		</ul>
		<!--<form>
			<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>
				
			</select>
		</form> -->
	</div>
	<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: info@energypac-fashions.com</div>
	</div>
	<div class="map-add store-col">
		<div id="MapCanvas"></div>
	</div>
	<div class="clearer"></div>
</div>


<?php 
get_footer(); 

?>

How to display best selling products in magento

1. Create a new file for Block:
Magento_root/app/code/local/Mage/Catalog/Block/Product/Bestseller.php


<?php
/**
 * 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')
            ->addOrderedQty()
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            ->setOrder('ordered_qty', 'desc');
        if (Mage::helper('catalog/product_flat')->isEnabled()) {
            $collection->getSelect()
                ->joinInner(array('e2' => 'catalog_product_flat_' . $storeId), 'e2.entity_id = e.entity_id');
        } else {
            $collection->addAttributeToSelect('*')
                ->addAttributeToSelect(array('name', 'price', 'small_image'));
        }
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
        if ($categoryId = $this->getCategory()) {
            $category = Mage::getModel('catalog/category')->load($categoryId);
            $collection->addCategoryFilter($category);
        }
        $collection->setPage(1, $this->getLimit());
        return $collection;
    }
}


2. Create a template file 
Magento_root/app/design/frontend/base/default/template/catalog/product/bestseller.phtml


<?php
/**
 * 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>
    <div class="block-content">
        <?php $products = $this->getCollection(); ?>
        <?php if (0 < $products->getSize()) { ?>
            <table class="bestseller-table">
                <tr>
                    <?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()) ?>" />
                            </a>
                            <h3 class="product-name">
                                <a href="<?php echo $p->getProductUrl() ?>" title="<?php echo $this->htmlEscape($p->getName())?>">
                                    <?php echo $this->htmlEscape($p->getName()) ?>
                                </a>
                            </h3>
                            <?php echo $this->getPriceHtml($p, true) ?>
                        </td>
                    <?php } ?>
                </tr>
                <tr>
                    <?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>
                            </button>
                        <?php else: ?>
                            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                    </td>
                    <?php } ?>
                </tr>
            </table>
        <?php } ?>
    </div>
</div>

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 theme directory

Go to /app/design/frontend

1.Declare your theme


<?xml version="1.0" encoding="UTF-8"?>
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 -->
     <media>
         <preview_image>media/preview.jpg</preview_image> <!-- the path to your theme's preview image -->
     </media>
 </theme>

2.Add registration.php

<?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'frontend/stark/my-first-theme',
    __DIR__
);

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 store.com/lib/Varien/File/Uploader.php:259

$params['object']->$params['method']($this->_file['tmp_name']);

to

$params['object']->{$params['method']}($this->_file['tmp_name']);

Catalogsearch form:

Catalogsearch > form.mini.phtml


$category = Mage::getModel('catalog/category');
if (is_object(Mage::registry('current_category'))) {
    $current_category_path = Mage::registry('current_category')->getPathIds();
} else {
    $current_category_path = array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string = $category->getChildren();
$children = explode(',', $children_string);
$extra_options = '';
foreach ($children as $c) {
    $selected = (in_array($c, $current_category_path)) ? 'SELECTED' : '';
    $extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";
}
?>
 
<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
    <fieldset>
        <legend><?php echo $this->__('Search Site') ?></legend>
        <span style="float: left; position: relative; top: 8px; left: 15px;">Search</span>
        <div class="mini-search">
            <select name="cat" id="cat" class="input-text">
                <option value="">All Products</option>
                <?= $extra_options ?>
            </select>
            <input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>"  placeholder="<?php echo $this->quoteEscape($this->__('Search entire store here...')) ?>" />
            <button type="submit" title="<?php echo $this->quoteEscape($this->__('Search')) ?>" class="button search-button" value="Go"><span><span><?php echo $this->__('Search') ?></span></span></button>
            <div id="search_autocomplete" class="search-autocomplete"></div>
            <script type="text/javascript">
                //<![CDATA[
                var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('Search your products') ?>');
                searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
                //]]>
            </script>
        </div>
    </fieldset>
</form>




Installation Problem:

|| Fatal error: Uncaught Error: Function name must be a string in /var/www/html/magento/app/code/core/Mage/Core/Model/Layout.php:555

$out .= $this->getBlock($callback[0])->$callback[1]();

to

$out .= $this->getBlock($callback[0])->{$callback[1]}();

|| Maximum execution time of 30 seconds exceeded in magento installation.

/* solve */
go to xampp/php/php.ini and search by 

max_execution_time=30  replace to 600
max_input_time=60      replace to 600
memory_limit=128M      replace to 1000m

|| PHP extension soap must be loaded

I edited php.ini and removed the leading semicolon ( ; ) from extension=php_soap.dll.
After restarting Apache I was able to proceed with the installation without any other issues.