Delete User From Woocommerce My Account Page

Deleting user is not good idea and it can be dangerous since it may cause whole WordPress Installation to break down. Having said that sometime we need to implement this functionality. For this you can implement the code below on function.php of your theme.

// Delete Account Functionality added on the edit form of my-account page.
add_action( 'woocommerce_after_my_account', 'woo_delete_account_button' ); 
function woo_delete_account_button() { 
	$delete_url = add_query_arg( 'wc-api', 'wc-delete-account', home_url( '/' ) ); 
	$delete_url = wp_nonce_url( $delete_url, 'wc_delete_user' ); 
	if ( ! current_user_can( 'manage_options' ) ) {
		<a href="<?php echo $delete_url; ?>" class="button">Delete Account</a> 
<?php 	}

add_action( 'woocommerce_api_' . strtolower( 'wc-delete-account' ), 'woo_handle_account_delete' ); 	
function woo_handle_account_delete() { 
	if ( ! current_user_can( 'manage_options' ) ) { 
		$security_check_result = check_admin_referer( 'wc_delete_user' ); 
		if ( $security_check_result ) { 
			wp_delete_user( get_current_user_id() ); 
			wp_redirect( home_url() ); 

Implementing the code above can sometime cause 500 error. In that case you can delete this line


We can also use the plugin for these functionality.

Delete Me

WP Delete User Accounts

Source :

Empty WordPress custom post Data from MySql database table

Sometime while working on huge WordPress site, we may need to remove the old custom post data. Today we will discuss on how we can perform this action. For this we need to have phpmyadmin access,

then in SQL run the below code one by one as shown in figure above,

DELETE FROM wp_posts WHERE post_type='post_type';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts);
DELETE FROM wp_term_relationships WHERE object_id NOT IN (SELECT id FROM wp_posts);

The first line deletes all posts with that post_type from wp_posts.

The second then removes any post metadata from wp_postmeta that is no longer tied to a post.

The third line removes and tags or categories from wp_term_relationships that were tied to that post type. This line should be omitted if you intend to create more posts of the given post_type in the future.

Source : Stackoverflow

Remove all category in magento

We can use the following steps to clear the all category for magento by running the sql query.

TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;
INSERT INTO `catalog_category_entity`
  (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),
  (2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
INSERT INTO `catalog_category_entity_int`
INSERT INTO `catalog_category_entity_varchar`
  (1,3,31,0,1,'Root Catalog'),
  (3,3,31,0,2,'Default Category'),

Source :

Convert a password the Magento way

Here’s how to convert passwords from plain text to the alghorithm used by Magento.

This can result useful when you need to import users from an external application which was managing passwords with no encryption.

So, let’s assume we already imported the customers from magento import tool and they can’t login because their password don’t fit Magento’s way, which is defined this way ( read it as a PHP developer ):


So, to convert all customers passwords you only need to login into mysql and run a single query:

mysql -u root -e "UPDATE customer_entity_varchar SET value = CONCAT( MD5(CONCAT('salt', value)), ':salt') WHERE attribute_id = '12'"
-- don't care about my local config ;-)

Source :

Reduce magento database size

Sometime we may face the problem of huge database size even after all product is deleted.
Run the following code in the sql,

TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;

Sometime we may get error so try to run code one by one. And enable cache for folder only not for database during installation.

Source :

Add .html to the URL of WordPress Pages

There may be requirement to change the wordpress url. The permalinks options of wordpress maynot be sometime sufficient as per client specification. To get .html the post can be done by changing permalinks in admin , but adding .html extension in the page url is not done by it. For that just add the below lines in functions.php of your theme

add_action('init', 'html_page_permalink', -1);
register_activation_hook(__FILE__, 'active');
register_deactivation_hook(__FILE__, 'deactive');
function html_page_permalink() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
add_filter('user_trailingslashit', 'no_page_slash',66,2);
function no_page_slash($string, $type){
	global $wp_rewrite;
	if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
		return untrailingslashit($string);
		return $string;
function active() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
function deactive() {
	global $wp_rewrite;
	$wp_rewrite->page_structure = str_replace(".html","",$wp_rewrite->page_structure);

If you arenot intrested to do so then you can install this plugin from
Above code are also taken from the that plugin

If you want to get .php then then just change .html to .php on above code.

WordPress Permalinks on Windows IIS

Normally we host the wordpress site in linux hosting and everythings works fine with permalinks. But sometime server may be different , let say for the Windows IIS server the permalinks may not works hence resulting the URL that isnot SEO friendly. So to overcome this issue we need to create web.config in root directory and add the following code in the file.

<?xml version="1.0" encoding="UTF-8"?>
        <rule name="wordpress" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <action type="Rewrite" url="index.php" />
Source :

Magento Adding search by category in advance search

Sometime we may need to change the options provided by the magento by default. Here are dealing with adding the “Search By Category” in the advance search page. For this case we need to change in the followinf files
➣ app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php
➣ app/code/core/Mage/CatalogSearch/Model/Advanced.php
➣ app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml

At the very end of app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php (before the closing brace), add:

public function getStoreCategories()
    $helper = Mage::helper('catalog/category');
    return $helper->getStoreCategories();

In app/code/core/Mage/CatalogSearch/Model/Advanced.php, replace the getSearchCriterias() function (line 157) with the code below:

     public function getSearchCriterias()
            $search = $this->_searchCriterias;
            /* display category filtering criteria */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) {
                $category = Mage::getModel('catalog/category')->load($_GET['category']);
                $search[] = array('name'=>'Category','value'=>$category->getName());
            return $search;

replace the next function, getProductCollection(), with:

public function getProductCollection(){
        if (is_null($this->_productCollection)) {
            $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
            /* include category filtering */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['category']),true);
        return $this->_productCollection;

In app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml, after this code:

 <?php foreach ($this->getSearchableAttributes() as $_attribute): ?>
        <?php $_code = $_attribute->getAttributeCode() ?>
            <label for="<?php echo $_code ?>"><?php echo $this->getAttributeLabel($_attribute) ?></label>
            <?php switch($this->getAttributeInputType($_attribute)):
                case 'number': ?>
                <div class="range field-row">
                    <input name="<?php echo $_code ?>[from]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />
                    <input name="<?php echo $_code ?>[to]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text"/>
                <?php break;
                case 'select': ?>
                    <?php echo $this->getAttributeSelectElement($_attribute) ?>
                <?php break;
                case 'yesno': ?>
                    <?php echo $this->getAttributeYesNoElement($_attribute) ?>
                <?php break;
                case 'date': ?>
                    <?php echo $this->getDateInput($_attribute, 'from') ?>
                    <?php echo $this->getDateInput($_attribute, 'to') ?>
                <?php break;
                default: ?>
                <input name="<?php echo $_code ?>" id="<?php echo $_code ?>" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute)) ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text <?php echo $this->getAttributeValidationClass($_attribute) ?>" type="text" />
            <?php endswitch; ?>
        <?php endforeach; ?>


            <label for="category_search_field">Search by Category:</label>
            <select name="category" id="category_search_field">
                <option value="">-- Any Category --</option>
                <?php foreach ($this->getStoreCategories() as $_category): ?>
                <?php if($_category->hasChildren()): ?>
                <option class="parent-cat" value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php foreach ($_category->getChildren() as $subcategory):
                if($subcategory->getIsActive()) : ?>
                    <option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option>
                <?php endif; endforeach; ?>
                <?php elseif($_category->getIsActive()): ?>
                <option value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php endif; ?>
                <?php endforeach ?>

Then open app/code/core/Mage/CatalogSearch/Model/Advanced.php
Open the file and search this function addFilters. In this function you can see following codes, replace this

    if ($allConditions) {
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));

with following codes:

    if (($allConditions) || (isset($values['category']) && is_numeric($values['category']))) {
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));

After above steps is done you will get the output as below
search by category

Source :

WordPress Turn Off Auto Update for Single Plugin

Wordpress Turn Off Auto Update for Single Plugin
WordPress Turn Off Auto Update for Single Plugin

While working with plugins sometimes we need to change the default values and attributes of the plugin which may be lost as soon as the plugin creator add the update to wordpress.
For to disable the auto update or hiide update message from the admin we can add the follwing line in finction.php .

function filter_plugin_updates( $value ) {    
unset( $value->response['plugin-directory-name/plugin-file.php'] );    
return $value;
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );

Here plugin-directory-name is the plugin folder name you want to disable and plugin-file.php is the main file of the plugin.

Source :

Create a pop-up WordPress email contact form 7

Contact form 7 can be used for different kinds of forms. Sometimes we may need to show the form in popup display. For to show the contact form in popup we can simply install Easy fancybox  and Contact Form 7 from wordpress plugin directoy and simple configure as below,
Firstly create contact form as you required and place contact form shortcode as below

<a href="#contact_form_pop" class="fancybox">Contact Us</a>

<div style="display:none" class="fancybox-hidden">
    <div id="contact_form_pop">
        [contact-form-7 404 "Not Found"]

For further detail you may visit to url below,

Source :