Add WooCommerce Product to Cart From URL Using Products SKU

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.

One response to “Add WooCommerce Product to Cart From URL Using Products SKU”

  1. greg

    in the same idea, is it possible to link a variation to an other Url (product)?
    Thanks in advance

    best Regards

Leave a Reply