How to Add JavaScript to your theme

From the last WordPress meetup, we discussed How to add javascript to your theme

Inside functions.php, hook into the wp-enqueue_scripts hook

add_action( 'wp_enqueue_scripts', 'wpmia_load-javascript_files');

function wpmia_load_javascript_files() {

wp_register_script( 'info-caroufredsel', get_template_directory_uri() . ' jquery.carouFredSel-5.5.0-packed.js', array ('jquery', '5.5.0', true);

...

...

wp_enqueue_script( 'info-carousel-instance' );

 

if ( is_front_page() ) {

wp_enqueue_script('home-page-main-flex-silder');

} 

}

AdWords Location Options Target and Exclude

You may have setup several Ad campaigns in Adwords. One of the setup options is related to Location. I did not give this one setting much importance. Instead, I would just enter the Country to target and forget about the rest. My assumption was that since I was “Targeting” visitors from just the one country, my ad would NOT be shown to anyone outside the targeted country.

Adwords Location Options
Ignore this at your peril. To target tightly, click on “People in my targeted location”

For example, I have Ad Campaigns targeting users exclusively in the United States. Or so I thought! My assumption was wrong, but I found out the hard way.

Accidental Discovery via Google Analytics

I was researching my site bounce rate when I stumbled upon the fact that my Adwords Ad was being displayed to users outside my “Target” country. This was totally unexpected because I did not intend to do that. I was trying to reach a specific country, but instead it turned out that users in other countries were being shown my Ad. Because this Ad was not relevant to them, my bounce rate associated with such visits was higher than 70%!

Through my newly learnt skills at segmenting data, I was able to narrow down specifically 3 countries whose visitors were showing an extremely high bounce rate. Note that these 3 countries were NOT my targeted countries.

Once I uncovered these wasted PPC clicks, I was determined to find out why AdWords was showing my ad. My first impulse was “ha, I found a bug in AdWords!”. Ofcourse, on deeper reflection, that was untrue. A bug like that could be of huge proportion and would have been caught much earlier.

Needless to say, I went digging through my Ad Campaign Settings. Specifically, I was seeking the answer within the Location Options settings.

Location Options (advanced) explained:

As it turns out, I had not read the instructions clearly. Part of the reason I overlooked this setting was because of the “recommended” default. The “Recommended” default option allows the ad to be shown to anyone in my targeted location, but also to anyone who “shows interest” in your targeted location. To make this clear, say you are selling “medicinal soap” through your Ads. Your “Target” country is United States. All is good so far, but what happens when a user searches for “medicinal soap in usa”? You guessed it right, the Ad is displayed.

What does this mean for me? In my case, I want a very tight control over what target country my ad is displayed in. Hence the “Recommended” defaults was not apt for my situation. I believe my choice would be “People in my targeted location“.

This setting would make sure that the Ad is never displayed outside of the Targeted country.

Also, keep in mind that the same settings apply for “Excluded” countries as well. The logic is the same, just conversely.

Conclusion

As I stated earlier, I was not looking at AdWords settings initially. My goal was to figure out why the bounce rate was so high for my site. This may be a small factor, but I am excited to see if the bounce rate will be lower, atleast for visits from the Adwords CPC medium.

 

How to setup Swiftype Crawler Based Search Engine for WooCommerce

I first started using Swiftype late last year (2015). The user experience offered by SwifType is phenomenal. It makes searching fun and not guesswork.

I started with the regular SwifType Search Engine along with the WordPress plugin from SwifType. While it provided basic functionality, the array of results did not include all potential matches. Digging deeper, I discovered that the WordPress plugin did not index pages that WooCommerce generates on the fly. Examples of these include the Product Category Archives and the Product Tag Archives. In addition, it would also not index the Brands archive either. Any custom taxonomy that was added was not being indexed. When I inquired about this, I was told that any pages that are dynamically generated by WooCommerce, are not indexed.

That explains why certain pages would not show up in the SwifType Search Results box. In a quest to get this working, I approached SwifType for guidance.

With help from SwifType, I added some code that solved the problem. With this code, SwifType indexes the entire site, including all dynamically generated pages. Please do note that you will have to create a new Search Engine in your SwifType account and select it as being “Crawler Based” versus WordPress plugin-based.

Be sure to replace the <unique-code-from-swiftype> with the actual code you are assigned by SwifType. Similarly, replace the <name-of-search-engine> on Line 11 with the actual name of your SwifType Search Engine.

 

Let me know what you think of this. Did it work? Did it help you? Did it break anything?

[WooCommerce] Checkout Progress Bar

WooCommerce Checkout Progress Bar in Action

As you read articles/posts on ecommerce optimization, specifically checkout optimization, a popular theme emerges: The Checkout Progress Bar. The idea is to provide your visitors some kind of visual feedback that they are making progress. It tells them how far along they are before the purchase is complete. Conversely, it tells them how much longer before they can own the product/service they are vying for.

With this in mind, I googled for a free plugin that would accomplish just that. My search ended fruitless (almost). I did hit this gem of a plugin called Progress Bar. This is a simple plugin that can be used anywhere on a WordPress site.

Steps

In this article, my aim is to create your own customized checkout progress bar without the use of any paid plugins. You will need

  • Download the Progress Bar plugin from the WordPress plugin repository
  • Make some code changes (PHP and JS included). Download from github.

The code changes are shown below. The first change is in your theme/child theme’s functions.php file. Two things are happening here:

  1. Hooking into the “woocommerce_checkout_before_customer_details” action hook to display the Progress Bar. We use the shortcode for the Progress Bar because it allows to send in parameters for styling and appearance.
  2. Loading the JavaScript file that will manipulate the Progress Bar based on how much of the Checkout Form has been validated.

The second file is the JS script that checks in real-time which mandatory fields have been validated. Then it calculates the progress (in pixels) by simply dividing the “number of fields validated” by the “number of fields that require validation”. It also accounts for the “Shipping Address Same as Billing Address” checkbox.


The end result is you get a progress bar for your WooCommerce Checkout Page.

WooCommerce Checkout  Progress Bar in Action
WooCommerce Checkout Progress Bar in Action

Notes on Customization

The CSS for the progress bar can be easily customized. Follow the instructions on this link. Also, note that the plugin has quite a few options that can be used for customizing the look and feel of the Progress Bar.

[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.