Skip shopping cart in WooCommerce

My beautiful wife put together a great WordPress blog, and installed the WooCommerce plugin in order to sell some items on her site. However, she didn’t like the conversion flow for end users; users had to add an item to the cart, confirm the quantities and subtotal, then enter payment information. Because my wife only had one SKU (product), and customers could only buy one at a time, she wanted to skip the shopping cart verification step, and allow customers to go straight from the product page to entering payment information after hitting a big red button.

Seems like a reasonable request. However, after much googling, I determined there was no out-of-the-box setting to enable users to skip the cart page after adding an item to the cart. Furthermore, although the WooCommerce plugin app does expose some AJAX endpoints, those endpoints do not provide the ability to reliably add one and only item of a given product to a cart before redirecting a user to the checkout page.

Luckily my beautiful wife is married to an ace programmer. It’s been several years since I’ve done any coding in PHP, but I went ahead and threw down a little modification for the WooCommerce plugin to enable her special use case. I’m releasing the code here into the public domain.

/** * Set cart item quantity action *
 * Only works for simple products (with integer IDs, no colors etc) *
 * @access public
 * @return void */
function woocommerce_set_cart_qty_action() { 
  global $woocommerce;
  foreach ($_REQUEST as $key => $quantity) {
    // only allow integer quantities
    if (! is_numeric($quantity)) continue;

    // attempt to extract product ID from query string key
    $update_directive_bits = preg_split('/^set-cart-qty_/', $key);
    if (count($update_directive_bits) >= 2 and is_numeric($update_directive_bits[1])) {
      $product_id = (int) $update_directive_bits[1]; 
      $cart_id = $woocommerce->cart->generate_cart_id($product_id);
      // See if this product and its options is already in the cart
      $cart_item_key = $woocommerce->cart->find_product_in_cart( $cart_id ); 
      // If cart_item_key is set, the item is already in the cart
      if ( $cart_item_key ) {
        $woocommerce->cart->set_quantity($cart_item_key, $quantity);
      } else {
        // Add the product to the cart 
        $woocommerce->cart->add_to_cart($product_id, $quantity);
      }
    }
  }
}

add_action( 'init', 'woocommerce_set_cart_qty_action' );

Please be aware this code has been tested, but is intended for hobbyist use. No warranty is implied. Your mileage may vary. Offer void where prohibited.

Installation instructions:
Copy and paste the code in your theme’s functions.php file.

Usage instructions:
Create a hyperlink with a query string argument like so:
<url>?set-cart-qty_<product ID>=<quantity>
Where <product ID> is the numerical ID of your product (something like “167”) and <quantity> is the quantity you want set in the user’s shopping cart (most likely this will just be “1”).

Example URL to send user to checkout with exactly one item of product with ID “167” in cart:

http://my.website.com/checkout?set-cart-qty_167=1

In my wife’s case the URL was set to the checkout page, so that she could set up a shiny red button that linked the user to checkout with the appropriate product already set in the cart, ready to check out.

Feel free to use it for your own site; it should be useful for any situation where you want to ensure a single product exists in the cart at a set quantity.

Shoe screws for running in snow, ice, and slush

IMG284

After living in Texas nearly all my life, I am experiencing my first real winter in Boulder, Colorado, and I am woefully underprepared. At the first signs of the coming gales and frigid temps I did the stereotypical Texan thing and bought the biggest, cheapest jacket I could find at Target.

Now that we have really settled into winter here and I have suffered through a few outings in the cold, I have a better appreciation for all the preparations that go into making a fun day outside fun in cold weather. (Hint: It’s not about getting the biggest, cheapest jacket you can find.)

One tricky thing about getting outside and running around in cold weather is snow, ice, and slush. Before I moved to Colorado, my idea of snow came from movies and commercials that featured blanketed white fields or uniformly covered mountains that were feet deep in the stuff. While those conditions do exist, that’s not where the fun is, at least not for me.

I’m a trail runner and I want to get out on the trails, wheeze up steep climbs and bomb the technical descents that I’m used to, albeit through the rosy-white sunglasses of winter. The snow on these trails gets stepped on, rained on, sunshined on, melted, frozen, melted again, refrozen, you get the idea. If it’s been pretty warm there may not be much of any snow on the trail, just the occasional icy patch. You don’t need snow shoes or anything designed for flotation, you just need something to keep you stuck to the ground when the going gets slippy.

I tried some YakTrax (YakTrax XTR to be exact. I assume the XTR stands for “XTReme”, probably a good choice if I decide to street luge down Fern Canyon.) Anyway, they were lousy. They slipped when I tried to apply power going uphill, and they pinched my feet on the downhill. I think they may work better for big stiff hiking boots, but they did not work well for trail running. To be fair, they are work fine for their intended purpose of hiking, but I really like taking descents aggressively and pushing myself on the uphills, and they were just not up to that kind of usage.

Enter shoe screws. I read and re-read and then forgot most of Matt Carpenter’s article on shoe screws at http://www.skyrunner.com/screwshoe.htm, then finally decided to go for it. My hardware store of choice has a million 40-foot tall rows, but only one half-row dedicated to screws, and they were missing the recommended screw length, so I made the crucial mistake of using 1/2″ screws instead of the 3/8″ screws. Ouch! The 1/2″ screws are fine in the heel area but not so great on the forefoot of thin-soled running shoes.

how to run on snow and ice with studded shoes

Ouch! Not in the middle!

The screws put a hole in my only pair of waterproof socks, and I had to spend a half hour unscrewing the worst of the little suckers on the side of the trail, but eventually I made it to the top of Green Mountain with them, then jogged down. They worked pretty well, except for the part where they stabbed into my feet if I stepped on a rock wrong. Traction was great, no slippage, no pinching, they just worked, and they were hardly noticeable on the pavement.

I later mail-ordered the shorter 3/8″ screws and installed them only on the perimeter of the shoe. This definitely helped ease the iron-coffin effect, but I can still feel the screws there on any kind of technical rocky terrain. They are like an anti-rock plate, in that they magnify whatever pointy bits you step on. I would go out on a limb and suggest that for technical trails, shoe screws may work better on thicker, stiffer soles, rather than the lightweight Altra Lone Peaks that I applied them to.

diy studded shoes for running on ice

Ahh, much better. Putting the screws only on the perimeter protects against slipping, and won’t create too much pressure in the middle of your foot.

My screw-studded Lone Peaks may not be ideal for rocky, technical trails, but they work great for snowy, icy non-technical trails and pavement. Since the tread on these shoes was getting worn down anyway, the screws have really given them new life. I have an old pair of heavier Vasque trail running shoes that I’ll try next. These shoes are thicker and stiffer in the sole, so I’m hoping they’ll work a little better on the rocky stuff.

Overall, I’m really enthusiastic about how well the shoe screws worked, and I can’t wait for some more snow so I can try some different variations. Winter is way too beautiful to spend next to a fireplace.


Update Feb 3, 2012:

I applied the snow screw treatment to a pretty chunky pair of Vasque trail runners and went for a long hike/jog up Green Mountain, across the west ridge and down Bear Canyon, then up Bear Peak and back down Bear Canyon to home, a challenging figure 8 route I call “Ochotauqua”. Route: MapMyRun Ochotauqua page

I applied a lot more screws to the forefoot this time and I noticed a significant improvement in traction on icy slopes, although I still found myself slipping on the steepest, iciest slopes.

ice screws for running shoes

The stiffer soles did prevent the screws from poking my feet, but the screws seemed to transmit a lot more shock to my feet than I’m used to, and over the course of the 4 hours or so it really added up to a lot of foot fatigue. I was really glad to get home and take them off by the end of the run.

One other thing to note, it seems like the extra screws translated to more noticeable drag on pavement. I think the strategy of putting the screws only on the outside is probably the best compromise.

Altra Lone Peak Review

IMG269

This was just silly; I don’t know how I let myself get into this situation. 3 weeks before running the Cactus Rose 50 mile race, I realized for the third time that my shoes were just not going to work. This last pair of shoes (Saucony Kinvara TR, for the record), just like the two before it, had begun falling apart within weeks. I was really worried now that if I didn’t get a good pair of shoes, and soon, I would be stuck with running the race in unfamiliar shoes, risking blisters, neuromas, and other foot maladies that could make for a long day out in Bandera. I knew I had to get it right with the next pair of shoes, because with taper coming up I was running out of time to test the shoes and break them in.

The Cactus Rose course in Bandera is chock full of loose, crumbling limestone, and although it doesn’t gain much in sheer elevation compared to the mountain races in Colorado, it is often going up and down really loose, rocky, cactus-covered terrain where you don’t want to take a fall. It is a technical course, with some decent climbs and descents, yet good portions of flats and rolling hills where you can let loose. I was looking for a shoe that was comfortable over long distance, protective, grippy, and lightweight. I had to choose quickly, and choose well, or else I’d have to run in my old-and-busted shoes from last season.

Based on several personal recommendations from friends, I chose the Altra Lone Peaks. They have a reputation as being a minimalist shoe, but they also had a moderately aggressive lugged outsole, a light duty rock plate, and a luxurious 10mm cushioned midsole. I was curious about two features of the Lone Peak: a “zero drop” platform (meaning the foot is flat, heel is level with the toe), and an extra-roomy toe box (said to aid comfort and allow toes to flex naturally.)

Altra is known for Zero Drop from heel to toe

Altra is known for Zero Drop from heel to toe.

I was a little concerned that I wouldn’t have enough time to adapt to the “zero drop” platform, and that the shoe would be too minimalist for the rocky course. I packed a spare pair of shoes at my midway drop bag, but I didn’t need them. The Altras worked really well for the course, keeping my feet comfortable and well cushioned over every last rock.

The outsole wears down quickly, leaving a smooth surface.

The outsole wears down quickly, leaving a smooth surface. Click for larger image.

The Altras really shine for this kind of race, but they don’t seem to hold up well in the long term. A few weeks after the race ended I realized the tread was nearly worn smooth on the outer edges of the sole. I still wear them anyway, but they are really prone to slipping on loose grit over rock. Another bummer is that the heel is completely floppy; there’s really no structure to the heel at all beyond mesh fabric. It’s not a big deal if you’re just running along, but when hiking, and on steep uphills and downhills, the shoes feel like they’re squirming around underneath my heels. It’s never caused me to wipe out, but it’s distracting and I feel like it slows me down on the downhills.

The heel is just mesh fabric with a little bit of yellow plastic

The heel is just mesh fabric with a bit of yellow plastic.

On the bright side, the roomy toe box is really nice (happy toes!), the shoe breathes very well, and it is really surprisingly comfortable, even over longer runs. The zero-drop platform ended up being a non-issue; I was running with a 4mm drop and didn’t feel much of a difference when running or in recovery. Surprisingly, with the thin-moderate cushioning in the midsole, they even feel decent on the pavement. This shoe has a reputation as being for minimalists only, but on my feet they feel like a really nice all-around pair of trail runners.

However, for the price of the Altras ($110 retail) I was hoping for a shoe that I could use for both racing and training for several months. I could learn to live with the odd fit in the heel, but the quick-wearing outsole is really not acceptable for the steep, rocky terrain I like to run. I will probably put ice screws in the pair I have and use them as a winter training shoe, but look for another shoe for general training and racing.