ecommerce WooCommerce Wordpress

[SOLVED] How to trigger emails of Failed Orders in WooCommerce

Update on February 3rd, 2016:

As of version 2.5 of WooCommerce, this functionality is now built into the WC Core. This plugin is not needed. See the WC 2.5 Changelog for more details.


Following the lead from this blog post by SkyVerge, I set upon to create email notifications when an order fails. Essentially, any time the credit card fails or the order processing is not successful, WooCommerce should notify the store owner that the order has failed.

Currently, WooCommerce is silent about Failed Orders. Note that there is a built in setting in WooCommerce for notifications about Canceled Orders, but not Failed Orders.

My first attempt at trying to modify this plugin by Justin Stern, failed. I tried to adapt the plugin for “Failed” instead of “Cancelled”. However, just replacing the instances of “Canceled” with “Failed” did not accomplish my objective.

After a lot of experimenting, I gave up and sought the help from the WooCommerce community. One of the most helpful WooNinjas, Caleb Burks, lent me a hand for this one. I take no credit for this. All I can say is that guy knows his coding very well.

In the future, I will try to explain the code. For now, here is the link to the completed plugin that sends out emails immediately after an order transitions into Failed status. To test this, simply change the status of an order to “Failed”. Emails should be fired off to the store owner.

Good luck to you. Let me know if it works or if you experience problems. This does work on my setup: WordPress 4.3.1, WooCommerce 2.4.6.


code Wordpress

WordCamp Miami 2015 Recap

I attended WordCamp Miami 2015 during May 28th-May 31st. The venue was Florida International University (FIU), my alma mater. The FIU campus has undergone a transformation. 16 years after I graduated, the campus has new buildings, fast food joints like a mall. I do feel proud of the fact that FIU campus at University Park has undergone such upgrades. The buildings sure look nice.

Enough about the venue, let us get down to what this post is really about. First day of the WordCamp was Theme and Front End Development course. There were talks about getting your feet dirty in the theme development. What follows are my tidbits on what I gathered during the talks. I was not able to attend all sessions. I focused more on the development/theme coding sessions.

Presentation/Slides are located here.

Day 1 : Core Concepts of WordPress Themes

  • Double quotes in PHP echo statements will automatically replace the variables with their respective values.
  • Template Hierarchy :
  • Presentation Slides
  • Any member of the template hierarchy will have a version of The Loop
  • The “body” of The Loop is where all posts are rendered
  • Show Current Template” plugin shows the actual template being loaded for a particular page/post.

Day 1: Building A Theme Using _S

Personally, this was my favorite talk. It was presented by Morten Rand-Hendrickson. Morten (“Mor10”) took a very hands-on approach by walking us through an actual project he did for Emily Carr university. For the project, he had to design a site for a mouse-only navigation where movies created by student artists would be showcased. He used the _s theme and built on top of that, incrementally achieving the final outcome.

  • Code Location – Project code used for Presentation. This theme was derived from _S (
  • Advanced Custom Fields is an easy plugin for adding custom fields to posts
  • CPT UI – Used for creating Custom Taxonomies
  • – Used for video controls
  • Isotope – automatically filter content on page. It does by appending class names.
  • When you download from, whatever you put in the “Name” field will be inserted into the code (example: wcmia_*).
  • will show you the preview of all fonts
  • display:flex (flex box can be used for auto prefixer) allows equal height columns without using float and clear. This is a CSS directive that enables equal height column layout. Can be used for orienting any content, horizontal or vertical.

Particularly, this talk was very insightful. Mor10 kept us engaged for 2 hours. That is a long talk by any coding standards. Mor10 was patient with our questions. He went step by step through his git changes. Moral of the story: For something so complex, break things down into smaller pieces. Connect the actual pieces from the problem into WordPress posts, taxonomies, custom fields etc.

Day 2: [Development Track] Beyond the Post: Pushing the limits of Custom Post Types

Look at this for an example of custom post type:

FieldManager – github

CMB2 – WebDevStudios

ACF ( may still require coding)

Day 2: [Content Track] How to Come Up With Articles for your Blog


  1. We only blog when we feel inspired
  2. We let our insecurities hold us back (“I am not a writer; I don’t have any thing important to say”). This prison is one of your own making.
  3. We only blog when we have a new insight.
  4. We simply need to learn to tell good stories. You do not need to be a story teller to be able to blog/write. The process of telling a story starts with Point, progresses to Context and then you Start.
  5. We will only blog when we are interesting.


  • Source : What did you see?
  • Story: What is the story?
  • Lesson: What is the point?
  • Audience: How do I shape it?
  • Point: What should they do?

Day 2: [Content Track] Constructing a Large Informational Site by Becky Design

Use Facets for filtering and narrowing down content from different taxonomies. The FacetWP plugin sounds very interesting in that it has a broad range of applications. I am excited to make this work for ecommerce sites using WooCommerce.

For creating custom taxonomies, you can either code your own via a plugin or use the CPT UI plugin.

Day 2: [Development Track] Cache Money Business by Mark Jaquith

2 Slow 2 Furious – Slow Sites are not good for performance

Caching Principles

  1. Do Less Work
  2. Work Less Often ($TTL = 5400;)
  3. Make Generic Output (less personalization)

BatCache – WordPress cache plugin – for full Page Cache Output

W3 Total Cache – Complex WordPress cache plugin

WP Super Cache – Medium complexity cachine plugin

CDN – Content Distribution Network – Points setup around the world for better performance

Nginx Cache Purging – 3rd party module for purging nginx cache

Varnish – Does not support SSL pages

Logged in = no page caching?

Cache Buddy – Subscribers and Users will not appear as logged in users

Cache WordPress Objects

APCu (Single Server Only), Memcache, Redis

Day 2: [Developer Track] WordPress and Third-Party API

API’s – WordPress API’s are written in in JSON (REpresentational State Transder)

How to build plugin’s which communicate via JSON API

json_decode(), $get., CURL are not what we use in WordPress

WordPress APIs – HTTP API is an important API for sending and receiving data to/from external sites.

  • wp_remote_get()
  • wp_remote_post()
  • is_wp_error($response)
  • wp_remote_retrieve_body()
  • set_transient()

Example was retrieving a random joke via JSON from the ICN Joke Database (Internet Chuck Norris Joke Database). You can integrate this code into a widget within WordPress or a shortcode.


That’s it! I only attended 2 of the 3 days. I skipped the Sunday schedule. All in all, it was a good event. As with any WordCamp, some talks were more useful to some people than others. It all depends on whether or note you received actionable stuff from any or some of the speakers. In my case, constructing a custom theme based on _s was enlightening. Additionally, I am excited to try out the FacetsWP plugin within an ecommerce site. By that measure, this WordCamp event was very useful for me. I look forward to WordCamp Miami 2016.


[SOLVED] Network Error in Google Chrome on installing extensions

This is an issue that was occurring quite repeatedly. At first, I was able to install Extensions and Add-Ons to Google Chrome. However, at a certain point, no matter what extension/add-on I tried, it failed with the following message:

An error has occurred, NETWORK_FAILED

It did not matter whether I cleared my cache and cookies (forever). I tried using Incognito tab as well. Still no luck.

After trying all the suggestions (short of uninstalling and re-installing Google Chrome), I stumbled upon this sequence of steps :

1. Go to “run”. (after you click on the Start button in Windows)
2. Type in regedit.
3. Click on the arrow on “HKEY_LOCAL_MACHINE”.
4. Click on the arrow on “Policies”.
5. Click on the arrow on “Google”.
6. Click on “Updates”.
7. Double-click on “UpdateDefault          REG_DWORD           0x00000001
8. Make sure it is on “Hexadecimal”.
9. Change your “Value data:” to 1.

Voila! That one registry change did the magic. I do not recall whether or not I had to restart after these registry changes. I should also mention that Google Chrome updates were failing because of this. Even when I tried to update Chrome using the Settings menu ->About, it would fail without any fail code.

I hope this helps someone!


[SOLVED] Unable to login to WordPress after WooCommerce upgrade

If you are having an issue logging into the WordPress Admin for your site, read on. Specifically, it seems that the WordPress login authentication completes. However, there is a redirect loop which is cyclic and recursive, so the browser eventually gives up.

My Environment:

  • Shared hosting based on LAMP
  • Static Cache, Dynamic Cache (varnish) and memcached enabled
  • WooCommerce along with a bunch of other useful plugins including Yoast SEO, Google Analytics by SEO, Revision Control, AKismet and a few others.
  • Theme: WooCanvas by WooThemes


A couple of days back, a new version of WooCommerce was available. Thinking nothing of it, I just clicked the upgrade button on it. I like to keep everything updated to avoid zero-day exploits. The upgrade seemed to complete successfully without any noticeable issues.

The following day, I logged into my hosting account and noticed I was using the Google PageSpeed module for caching. With my host, if you enable Google PageSpeed, it disables all the other 3 kinds of caching mechanisms. These caching mechanisms are Static Cache, Dynamic Cache and memcached. All 3 of these caching schemes are at the hosting interface. I should mention that the site is hosted at Siteground.

Caching (at hosting server)

When I noticed that Google PageSpeed was not giving me acceptable speed, I decided to disable it and re-enable the 3 Siteground provided caching schemes. I enabled Static Caching, Dynamic Caching (varnish) and also memcached. From what I understand, memcached stores the dynamic database related objects in RAM to avoid database server latency.

Little did I know that this would cause me huge trouble. Specifically, I was unable to login to the WordPress Admin of the site after I did this. At the time though, I did not know that enabling “memcached” had somehow led to this lockout.

Redirection after login

Specifically, I was being redirected from any Admin page to the ‘wc-about’ page within WooCommerce Admin. I used the FireBug console to determine as much. The redirect however would not work and the browser would give up after a few times of constant redirect. I believe it was an endless redirect loop.


At first, I logged a ticket with Siteground to determine what had caused this disruption. As usual Siteground responded promptly (a good thing). However, their response was not exactly helpful. They said they had tried several different things, but nothing worked. This included renaming the “plugins” folder, disabling all the plugins, reloading stock .htaccess. I should also clarify that the site itself was totally operational from the front end. There were no issues at all browsing the front end of the site. It also loaded a bit quicker now that all 3 caching schemes were enabled.

As disappointed as I was with the response from Siteground, I was determined to get to the root cause of the issue. After a couple of hours of trying a few different things, I finally narrowed it down. It turned out that if I disabling the “WooCommerce” plugin, the problem disappeared. This was consistent because the “wc-about” page is a WooCommerce Admin page. It made sense that WooCommerce was somehow tied into the equation.

The next step however was not so simple. I stumbled upon the caching setup once again. This time, however, I only disabled memcached. Voila! That seemed to fix it.

Possible memcached conflict/interaction with WooCommerce upgrade

At this point, I believe that there is some play between enabling memcached on a newly upgraded WooCommerce plugin. Somehow, the upgrade process did not complete fully maybe? I do not recall if the “wc-about” page was displayed after WooCommerce was upgraded. Once I disabled “memcached“, logging into the WordPress Admin, I was greeted immediately by the “wc-about” page.

I hope this helps someone who is locked out of their WordPress Admin after upgrading WooCommerce. Who knows if this could have happened while upgrading any other plugin as well?  Let me know if you have seen this issue.


Q & A with Chris Christoff on WordPress ecommerce

This past Saturday (October 4, 2014), I attended WordCamp Tampa.  While there, I took up Chris Christoff‘s offer to answer any ecommerce related WordPress questions. Chris was kind enough to clearly explain all his answers. For that I am very appreciative. I hope Chris is a speaker at more WordCamps. Even though I could not attend any sessions in full, the 40 minutes Q & A with Chris made this a most productive WordCamp for me! Here is the summary of my questions and answers by Chris:

Q1. I use WooCommerce. Sometimes, I have product(s) whose layout I would like to change. i.e. the default layout from WooCommerce does not apply well to these products. How do I change the layouts of these certain products in an upgrade-safe way?

A1. First make a child theme. Copy the content-single-product.php inside the child theme. inside the”, check using Conditional Tags if the current product requires a special layout. For checking, you can use a category slug or the Product ID itself.

If the Product does require a special layout, place those layouts within the “if” clause.

NOTE: If you have only a handful of products that require this layout, it is acceptable to use this “if” approach. However, for more products, it is advisable to use a “switch … case” construct. Within each “case” clause, “include” the PHP file that contains each product’s layout definition.

If WooCommerce changes the “Add To Cart” function name, check your theme to make sure function names are named correctly. This is very rare and unlikely.

TIP: Use git to look up the differences between your theme and the one that WooCanvas is about to release. You can simply place a copy of your current files and compare with the latest WooCommerce version of those files.

Q2. I  have an IFRAME from an external site that allows the visitor to customize a product. When different options are selected, the jQuery script will change the product’s appearance. Is there a way to simply retrieve some output (price and options) from this script and pass them on to WooCommerce to “Add To Cart” this custom product?

A2. Since its an external script that does not output anything, nothing can be extracted from this script.

Instead, Chris suggested to compile the pictures of all the permutations/options.  (Use amazon mechanical turk for downloading all the images). Use those images as attribute images. This way, this product can be easily defined as a Variable product with all the different options. In other words, do not use the IFRAME because it can not be “Add”ed to Cart.

Q3. In WooCommerce, we have products with Variations. Say for example, a Product has 3 colors and 3 sizes. That makes 9 different combinations. The picture of the Small, Medium and Large combinations is the same. i.e. no different picture is required for combinations that are of the same color. How do I assign the same picture to combinations of the same color without repeating it 9 times?

A3. First step, do not “link all variations”. Instead, click on “Add Variation”. Select the Color, then select “Any Size”. Then load the picture for that color. This way, you only upload the picture for each color just once. (versus 3 times, for each of the Small, Medium and Large sizes).

The downside with this approach is that you can not have differently priced Size based options. You can not specify Stock for the Small vs Medium vs Large either.

Q4.Speeding up WooCommerce. Tips?

A4. Caching. Host provided caching is the best. Send a ticket to let your host know that we are using WooCommerce. This way, they can exclude Checkout, Purchase Confirmation and My Account Page.

Look into Amazon cloud front for caching/CDN solution. Also for CDN’s, Chris’s recommendation was MaxCDN or Amazon S3. CloudFlare did not have high marks.

A surefire way to speed up the site is using hosting that use SSD drives instead of SATA. Additionally, Memory Caching at host can make a major impact. Recommendations Digital Ocean or Liquid Web. CloudFlare not recommended. Amazon or Max CDN is recommended.

Q5. Checkout page customization

A5. Copy the checkout page template to the child theme and then make changes. This way, the changes will be upgrade-safe.

Q6. For cross sells to show on single product:  I would like to show related products for certain products.

A6. Call woocommerce_cross_sell_display() inside the single-product.php

Q7. If we want to write a plugin for product attributes so that all products with no default attributes should automatically have some default, what would be the best way to go about it?

A7. This has been debated internally several times before.

Look at the Core code in wordpress inside save_post(). Check if a product has attributes. If it does have default attributes, no change. Otherwise, update the meta data for that product to assign default attributes.

That is all the questions I had. If I meet Chris again, I will ask him more questions. He is the most enlightened WooCommerce expert I have ever met!