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.

Upload Images Using JS

I recently needed to update a form to update through AJAX so the page didn’t reload when submitted. The issue was that we had some images on this form. In the past I have used things like plupload, but that didn’t seem like the right approach in this instance.

At first I looked into the “fetch” api and saw a good post from Tania Rascia, but unfortunately the fetch API still isn’t fully adopted…DAMN YOU MICROSOFT!

Thankfully I was able to find a jQuery version of this same idea over on Makeitweb.com by Yogesh Singh.

I also needed to make sure I sent along post data with the FormData to update the rest of the form. Here is an example of the JS code I ended up using:

On the server script you can access this data just like any other form submission.


There we go! Now we can submit our form, including images, to our server script!

NOTE: We are using a custom function to serialize our form data. You can find that function here.