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.

 

Google Autofill Covers Address Autocomplete

I have run into this a few times and it always bothers me. Google has an auto fill function for forms that is sometimes really handy as a user, but sometimes breaks ui elements if you are a dev.

This is especially bad with the Google Address search because it seems to reset your autofill / autocomplete attributes each time you focus on the element.

If you are running into this issue here is a good thread with a couple good solutions for hiding the autofill.

The jQuery solution is what I found worked best for myself.

 

JS Highlight Text

I needed to setup some text search functionality on a page and the client really wanted the searched words to be highlighted.

I found a great library for exactly this over on The Art of the Web.

They do a great job of explaining this library so please check them out to learn more!

Hash Link Offset

When you have a hash link on your page ( href=”#target” ) sometimes the browser scrolls too low and cuts off or puts too close to the top the target element.

You can offset this hash link by hooking into the ‘hashchange’ event.

This does NOT resolve linking directly to this hash tag, but will fix the on page hash link.

To do that you can setup the following functions.

Thanks to Eric Olsen over at stack overflow!

Google Font Print Issues, font-display: swap!

I had an issue that was driving me up a wall. Certain fonts, technically only the normal font weight of the Open Sans font, was not printing on the first “print” attempt. After clicking print a second time the page text would print as normal.

This issue was due to how Chrome loads / displays fonts. Feel free to read up on ‘font-display’ and Chromes issue with printing web loaded fonts. The short answer is basically Chrome was trying to reload the font for the print page instead of using the font it used on the screen.

The solution is thankfully VERY simple. Just add “&display=swap” to your Google Font url string in order to avoid this issue. This also has a variety of other speed benefits, so you should ALWAYS be adding display=swap to your Google Web fonts and Google Fonts now supports this by default.