WP e-Commerce Visitor Profiles

/* * About WPEC customer profiles. * * WPEC customer profiles are nothing more than WordPress users created and used to hold information * related to a visitors experience on a WPEC site. Using WordPress users rather than a special purpose * database table makes all of the existing WordPress user functionality available when working with * customer profiles. * * Additionally, WordPress user functionality makes use of the built in caching capabilities within WordPress, * this makes user profile access quick. All of this comes without the costs of additional code to maintain. * * WPEC, themes and plug-ins can add information to a customer profile at any time. The functions making up the * API are in the wpsc-meta-customer.php. You’ll notice that the API for working with customer profiles mirrors * the WordPress API used to work with other types of meta data. Customer meta can be manipulated just as * you would manipulate user meta, post meta, or any of the other types of meta available with a WordPress site. * * There are a few specifics about customer profiles that you may want to be aware of, but you shouldn’t need * to know unless you are contributing to the WPEC meta functionality. * * Customer profile users when created are prefixed with ‘wpsc‘. Don’t rely on this when creating database queries * because other plug-ins, or even administrators, can change user names. * * If you properly use the WPEC meta API, any meta you add to a customer profile will be prefixed with a * standard, multi-site safe, prefix. This prefix is automatically removed when you retrieve meta values using * the WPEC meta API. * * Customer profiles have added to them a meta value ‘last_active’ immediately upon creation. This meta value * contains the UNIX timestamp (see PHP time() function) of the last meaningful change to the profile. * whatever end purposes you might want, but it’s core purposes are two-fold. (1) This value makes it possible to detect * abandoned carts and return cart stock, (2) and it makes it possible to detect temporary profiles that are no longer needed. * This value can also be used to implement advanced features like email reminders to customers that they have items in * their carts, or haven’t visited a store for a period of time. * * Customer profiles when created have added to them a role of Anonymous. This makes it possible to distinguish which users * are created from WPEC operations from the users that are created by typical WordPress blog actions and other plug-ins. * * Customer profiles when automatically created have added to them a wpsc meta value “temporary_profile”. The presence of this * value indicates a WordPress user that will likely be deleted if the visitor doesn’t take any future actions. * Because the above values (profile name, roles, etc.) can be altered by user interface or other plug-ins, having this * dedicated meta value gives us a safe and fast way of finding temporary profiles. * * If present, the value of the “temporary_profile” meta is automatically adjusted when the last_active time * is adjusted. The value will be the unix time stamp after which the profile can be marked for deletion. When * the meta is first added to the newly created user profile the “safe to delete time” is set to the current time * plus 2 hours. Using this method, visitor profiles that are created by mechanisms like aggregator framing web site pages * for user preview rather than browsing are more quickly deleted. * * Subsequent updates to last active move the safe to delete time to the last active time plus 48 * hours. This also means that customer profiles create for visitors that only do a single page view will * quickly be purged from the WordPress user table. On the other hand visitors that view more than a single * page of a site will have profiles available for a longer time. * */

Contributing to WP-e-Commerce Developement

Why are we writing this article?

After about the third or fourth time we had to rebuild our local GIT repositories because we inadvertently unleashed the fury of an inappropriate git command it’s time to write down how to do the core operations needed to setup, test, develop, patch  and submit changes to WP-e-Commerce via GITHUB.

We will use our forked repository at git@github.com:JeffPyeBrook/WP-e-Commerce.git as an example. But first some rules

Rule #1: Our repositories’ MASTER will be a copy of the WPEC repository MASTER Rule #2: No local changes to our MASTERs Rule #3: We will update our local MASTERs frequently Rule #4: We will test merge all  of our PR requests into a local version of UPSTREAM master named dev-master 

Getting ready, clone the WPEC repositories.

Easy enough from your local git shell make a clone of the repository into your local WordPress plugins directory.

git clone git@github.com:JeffPyeBrook/WP-e-Commerce.git WP-e-Commerce

Inside the plugins\WP-e-Commerce directory, we want to point the UPSTREAM to WPEC’s MASTER repository. Change to the directory and add the remote

git add remote upstream git@github.com:wp-e-commerce/WP-e-Commerce.git

Create our development version of the master branch

git checkout -b dev-master

Dev master should also available on GITHUB

git push -u origin dev-master

Frequently we will want to pull into the local MASTER’s all changes from upstream. To do this these commands will work. Doing these at setup will also confirm your configuration is correct.

git checkout master git fetch upstream git rebase upstream/master

Rule #5: We will name feature branches descriptively in a way to associate them with what is being implemented or changed, for example visitor-meta

Rule #6: When we are ready to submit a PR request, we will create a mirror of our feature branch that is based of off UPSTREAM/MASTER and prefix it with pr.  For example pr-visitor-meta.

 

 

 

 

 

 

 

Untitled

Feature Highlights

  • Shoppers Earning points based on amount spent
  • Import historical purchases
  • Points history available to shoppers on their WP-eCommerce account page
  • Works with the WP e-Commerce Coupon System
  • Let customers change points into coupons
  • Customer point redemption self-service
  • Customers can easily redeem points on their WP-eCommerce account page

Should you run away from DreamHost?

We curate and host WordPress and WP-eCommerce sites for ourselves and our customers. One of the hosting providers we use, and recommended WAS DreamHost. Their support and pricing had always been good. Their attitude used to be cooperative, communicative and considerate.

Then, last night, while at dinner with the bride, my phone vibrates indicating a priority message. As of that message, DreamHost is no longer on our recommended list.

DreamHost sent out a blast email notifying all of their customers that in 4 business days, and in the middle of holiday shopping season, DreamHost is making a change to their hosting configuration. The change DreamHost is making is a little hard core, removing “sudo” access to the servers. For people that don’t know, sudo is the tool that lets a user log in to make an administrative or configuration change to a server.

For your entertainment value, the message is below.

dumb-dreamhost
Dumb DreamHost

Why this matters? Every once in awhile something goes wrong on a server often a simple fix is restarting a process, or flushing a cache. In the case of e-commerce sites we sometimes have to make subtle adjustments to configurations in response to reports from periodic security scans or security patch notices. After this change, making any critical change will be impossible.

So, after the change, if a web site requires a little tweak or has an issue that is critical to it’s ongoing operations, just turn out the lights.

And no, we don’t think turn out the lights is an exaggeration! All of the commerce sites we curate for our customers are PCI Compliant and are periodically scanned by independent third parties. If a scan detects an issue, as sometimes happens with a recently discovered operating system or application software vulnerability, we get notified. If the issue is severe and is not promptly corrected, the PCI company will notify your credit card processor. If your credit card processor decides that the issue puts them at risk, your payment processing can be turned off.

With this change your sites’ performance is also at risk. Even a common performance enhancement to a WordPress site like turning on memcached now becomes impossible. For some of our commerce and blog sites memcached is important. Memcached speeds WordPress response times up by 5-10 times, and lets us handle spikes in traffic without any degradation in performance. So if your e-commerce site is lucky enough to get busy, even this most obvious performance tweak is not going to be useful.,

For any DreamHost customers that need to find the words to share with DreamHost to express their concern over this change feel free to borrow from the hastily written note we sent to DreamHost last night:

I just received an email that you are making a change to the VPS configuration for my sites in the middle of the christmas shopping season. WITH LESS THAN 10 BUSINESS DAYS NOTICE! “We will be removing admin (sudo) access from all DreamHost VPS instances.” Removing the administrative access to our server instance will cause substantial loss to our business. If you make this change it is a near certainty that my site will not be supportable, will fail, and you will cause a substantial financial loss to our company. The mitigation of your actions, even if they were technically possible in the inadequate time you have provided, will cost of tens of thousands of dollars to implement. The inadequate notice period makes it impossible for us to find another technical resource to host the site, move it and test it in the next few hours before the busiest shopping days of the year are upon us. This change and how you are planning to make it, most notably including the insufficient notice is negligent, and exudes arrogance and incompetence. I insist that I immediately get a call back from a manager explaining this change and why your management team thinks the timing is acceptable. I insist that you provide a viable alternative or cancel the plans that you have made unilaterally. I insist that you forward me the contact address that I need to use for legal notices and correspondence. Please include the postal address, the person’s name, and the telephone number so that I can have correspondence sent. Flabbergasted by this bonehead move, Pye Brook Company, Inc.  

This morning, we start work and check our host status DreamHost server control panel and find this notice:

 

dump-dreamhost-response
Dumb Dreamhost Response

You can get whiplash reading the back-peddling in this note. A very disturbing take-away from this posting is that DreamHost fails to recognize the critical timing of this change and how it could impact customers. Even worse, is the admission that they have not taken the time understand the impact of this change before making the decision to implement the change.

Our takes on this situation are these:

  1. This change makes it technically impossible to implement the standard recommended configuration for highly performing WordPress blogs and e-Commerce sites.
  2. This change makes it technically impossible for us to respond to critical situations that arise from time to time with the sites we host.
  3. MOST CRITICALLY: We can’t rely on a hosting provider whose internal decision making process is so flawed that changes like this are put in process during critical times, without making the necessary effort to understand the impacts, and without sufficient notice.

We are fortunate in that we also have sites running on Amazon AWS and Digital Ocean, so we have a path out the DreamHost debacle.

So the answer is yes, we think you should run away.

If you are already using our curated WordPress or WP-eCommerce services you will be migrated transparently after we consult with you and make sure it won’t impact any planned/expected commerce or marketing events.

If you work on your own, and you feel at risk by this dreamhost move we can migrate your WordPress blog or e-commerce site to your stand-alone AWS server / Digital Ocean server or our curated offering for a one time flat fee.

 

WP-eCommerce Tip: Hide Comments on Single Product Pages

If you have a store with hundreds of products it can be a little annoying to have to turn off comments on every product page.  But, you can add a few lines of code to a file in your mu-plugins directory, or your theme’s functions.php file.

This will turn off comments on your single product pages.

/**
 * Filter whether the current post is open for comments.
 *
 * @param bool        $open    Whether the current post is open for comments.
 * @param int|WP_Post $post_id The post ID or WP_Post object.
 */
function wpec_no_single_product_page_comments( $open, $post_id ) {
   if ( $open && is_singular() ) {
      $post_type = get_post_type( $post_id );
      if ( 'wpsc-product' == $post_type ) {
         $open = false;
      }
   }

   return $open;
}

add_filter( 'comments_open', 'wpec_no_single_product_page_comments', 10, 2 );

Use PhpStorm When Developing for WordPress

The title says it all.

The marketing folks at JetBrains might have the easiest job on the planet. At other companies marketing is about spin, at JetBrains it is mostly about just telling developers what the product does.

For a detailed feature description you want to visit https://www.jetbrains.com/phpstorm/features/

Let’s keep this short and to the point

There is much to this product, too much to go through every feature and function.  After a couple years of use I am still finding something new every time I look.

The key features that WordPress theme and plugin developers will very quickly appreciate are:

  • Easy navigation access to a WordPress function’s documentation, or  the function itself, with a single click.
  • Accurate code completion for WordPress function calls, with parameter descriptions. Same for code completion for your custom code, which leads to the next point…
  • Quick automatic creation of accurate phpDoc blocks, and basic class methods.
  • Thorough inspections of phpCode for compliance with WordPress coding conventions, as well as potential PHP Issues
  • Integration of jshint and many other common tools within the development environment.
  • Integrated, zero configuration, debugging
  • Ability to configure an entire WordPress site as a project, or just an individual theme or plugin as a project. It’s not an issue to have a WordPress site with 50 plugins loaded into the IDE and indexed while coding and testing.
  • Quickly change inspection profile between one PHP version and another. General use plugins and themes have to work with PHP 5.2, so changing the version number and running an inspection will quickly tell you where your backwards compatibility issues are!

Any developer should appreciate that JetBrains updates PhpStorm product very often.  Sometimes every week. If you join the EAP program you can get these rapid updates and use them immediately.  The quality of each of these updates is really very good, and the documentation includes release notes so you can make an informed decision if a specific update is appropriate for you.

Updates include a mix of new features, performance improvements and bug fixes.  The issue database is public, and current.  Making the issue tracking information public on a commercial project shows great confidence in their product and their development team.  Any serious developer should note this, and have a high degree of confidence in PhpStorm as their IDE of choice.

How to Show WP-eCommerce Products on Blog Main Page

If you are using the WP-eCommerce plugin to sell items in support of your WordPress blog you may have been wondering if it’s possible to have your products show up on your main page intermixed with your regular blog posts.

The WordPress main post “loop” can be adjusted using the pre_get_posts filter.

The filter lets you change how WordPress builds the list of posts displayed for your blog.

You can add code like what is below to a file in your mu-plugins directory or theme functions.php file.

add_action( 'pre_get_posts', 'pbci_show_products_in_loop' );

/**
 * @param WP_Query $query
 */
function pbci_show_products_in_loop( $query ) {
    if ( ! is_admin() ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'post_type', array( 'post', 'wpsc-product' ) );
            $query->set( 'orderby', 'modified' );
            $query->set( 'order', 'DESC' );
        }

        if ( $query->is_main_query() && $query->is_search ) {
            $query->set( 'post_type', array( 'post', 'wpsc-product' ) );
        }
    }
}


Notice the check if ( ! is_admin() ) {.  This is to be sure we don't change the post listings in the WordPress dashboard.

The check if ( $query->is_home() && $query->is_main_query() ) { tests to see if we are on the main page in the main loop.

Then $query->set( 'post_type', array( 'post', 'wpsc-product' ) ); sets the desired post types to regular posts and product posts.

If you don’t want to play with the code, but want to give this idea a try, we have put the code into a FREE PLUGIN in our store.

WordPress Tip – Stopping Post Navigation

Every once in a while you may want to display a post but not have the theme show navigation links.  This can happen if you are showing an error message, a private, or perhaps a custom post type.

Your first instinct is probably to modify the theme files. Doing this might be quick, but every time the theme is updated, or every time you change themes you are going to have to be changed the theme files.  So what is the best way.

One technique is to make WordPress think that there aren’t any next or previous posts to link to.  Create a file in your mu-plugins directory with code similar to what is below and the navigation links will never show.  If you wrap the add_filter calls in a conditional that matches your needs you will be all set, no theme mods required!

function stop_post_navigation( $where ) {
   return 'WHERE 1 = 0 ';
}

add_filter( 'get_next_post_where',  'stop_post_navigation', 10, 1 );
add_filter( 'get_previous_post_where',  'stop_post_navigation', 10, 1 );

Creating a Coupon for a Free Product in WP-eCommerce

From time to time you may want to give a product away as a promotion.  This is how to create a coupon for a free product.

 

In the WordPress Dashboard, on the PRODUCTS menu select COUPONS

coupon menu

 

 

 

 

 

 

 

 

Add the coupon for your product using the new coupon form:

add-coupon-button

 

 

 

 

Use a unique coupon code, in the example we use “FreeGift”

Set the discount amount to 100%, this will reduce the cart sub-total by the value of the product being given away

Set a start and end date

DO NOT CHECK  “This coupon affects each product at checkout”, if you check this the shopper will get the whole cart for free 🙁

In Conditions select “Item Name” and “Is Equal To” and enter the name of the product you are giving away.

create-coupon




That’s it!

Live Grid for WP-eCommerce Styling Enhancement

We are testing out an update to the Live Grid for WP-eCommerce plugin that enhances the styling for product prices.

Styling now includes an option for free products, and highlights product prices that are on sale.

price styling