Regenerate Woocommerce Download Permissions

We recently imported a large number of orders and files from and older legacy / custom Ecommerce site into a Woocommerce site.

There are a lot of tales to tell in this adventure, but a big one was getting all of these files attached correctly to the product variations downloadable file.

It took a while to find a good solution, but thankfully Chris Hawkins had a good answer for me over on Stack Overflow.

Here is essentially what my solution looked like:

This only needs to be run once for each order so this can be run from almost anywhere. Make sure to update your offset until you make it through all your orders AND that you already have all your files in place.

That is it! I hope this helps someone!

Woocommerce Custom Endpoint

Sometimes we need to add a new account menu item for Woocommerce. If you have the same problem the code below should get you 90% of the way there. Just need to build out your own template part.

 

Multiple Custom Query with paginate_links

Sometimes I need pagination for multiple queries on a single page. Whenever possible I use the built in WordPress functions for this purpose. However, WordPress’ pageinate_links() is really meant for WP custom queries…and preferably one query per page.

Here is an example of how you can use this built in function for your own queries! We are using an example which involves three different email lists we need to display.

First, setup your queries:

Second, display your results: Note, I am leaving out a lot of the display code, but all the relevant pagination code should be here.

Notice at the bottom of this loop we are calling our pagination function for each list. The important thing to note here is that we are using a separate ‘type’ variable so we know which list we are paginating.

Lastly, here is the actual pagination function:

 

Custom Woocommerce ACF Category Filters

We had a client recently that needed to be able to create product filters based on the product categories they were assigned to. This presented a problem because we didn’t want to clog up the taxonomy / category pages with a bunch of filter options and the user also needed to be able to edit these categories in the future.

We took the approach of adding some ACF fields to the product categories and then inserting a meta box on the products based on their selected categories which would list the ACF fields as checkboxes, similar to selecting a taxonomy.

It is hard to explain so here is a bunch of code and images to explain.

Here is our custom meta box displaying the filters that were created in the category page. Notice this is actually displaying the filters from ALL selected categories.
Here are the filters created in one category.
This is what the front end looks like. The checkboxes are FontAwesome icons.

Finally, here is the code needed to accomplish this.

All of this code goes into your “functions.php” file

Here is an example of what the front end HTML might look like.

 

Reorder Posts By Menu Order, then Post Title

This can be done using $args = array( ‘orderby’ => array(‘menu_order’,’title’)) however then you are using a 0 index menu_order (0 menu order goes first) and the first letter of the post title (rather than by say, the last name in the post title). So this is just a function to give a little more control over that ordering

 

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!