Add WooCommerce Product to Cart From URL Using Products SKU

Remi | June 3, 2016 | in Free

I am working on a personal project for Automattic, and in this project I needed to tweak the way WooCommerce adds products to cart.

Basically, when you add a product to cart, you probably noticed it if Ajax isn’t enabled in your shop, your are redirected to page having the following URL structure:

Where XX is the product added to cart ID. I wanted to be able to use the SKU in the URL instead of the product ID, in other words I wanted this:

So, I wrote this plugin:

Now, I can type, let’s say and the product having the SKU equal to 5678 will be added to cart. If no product has this SKU, then the product having 5678 as its ID will be added to cart.

Please note: due to a security check within WooCommerce, that method will work only with SKU containing numbers only. Letters aren’t accepted.

The author

About the author Remi: Hey! My name is Rémi Corson, I'm a French WordPress Developer, I code stuff and I write from time to time ;-)

One comment

Leave a reply