List Woocommerce Cart Item Attributes

90% of the time I am very thankful for plugins like Woocommerce, that handle so much of the architecture associated with an e-commerce site.

10% of the time I curse their name in the more profane manner possible. This seems to happen most often when using variable products.

For reasons that defy reason, Woocommerce does not list the variable product’s attributes when it is in your cart. There is also no Woocommerce function, afaik, to easily list a cart items selected attributes. Why on earth would someone want to know what type of product they put in their cart! Bah!

Anyway, here is some simple code to list the attributes for the variable products in your cart:

Hopefully that will save you 1% more time of cursing the name Woocommerce!

Add Custom Fields to Woo Variations

Sometimes each variation needs its own custom fields. Say if you need to add a unique UPC or EAN code. This turned out to be surprisingly simple. Thanks to Remi Corson for the code.

PS. You should check out Remi’s page for pretty much ANYTHING Woocommerce related. It is basically an infinite well of Woo knowledge.

Slick Carousel Basic Usage

Slick Carousel is pretty awesome. Not great in every instance but perfect for many. It is also very mobile friendly including swipe events.

Here is some basic setup code to get the slick slider working. This is being used in combination with Woocommerce thumbnails.

Now just initialize this slider somewhere.

 

Add Custom Value to Woocommerce Order

Woocommerce documentation, while thorough, can be hard to follow sometimes. Here are some functions I found somewhere on the Woocommerce site (which I can never find) that allows adding some custom values to the checkout order form and then attaching that value to the order.

 

 

Set Woocommerce State

Most clients want to limit the number of states they sell to…but for reasons beyond comprehension Woocommerce does not make this easy.

Here is some code to exclude a few state.

You  could also set the $states[‘US’] array to just the states you want if that would be easier.

Add Item to WooCommerce From Outside Shop

Sometimes I need to setup donations or memberships or some other item that needs to be added to a users cart but NOT be listed in the shop. First thing we should do is make sure to hide these items in the shop. For this to work you will need to set your Product Category. It can be anything you want of course. Then place this code in your functions.php file

Now that these items are hidden on the shop page (you may also find you need to hide them on other pages depending on your setup but just add those pages to the “if” check. Next we need to setup the code to add this to the cart.

Here is the basic code to add this to the cart. I have also setup a check to make sure no other items of the same category are in the cart, and if they are remove them and add this one. Then, if successful, direct the user to the cart page.