Code Sample: Keep GIF Animation When Adding Media to Post Content in WordPress

When you upload an animated GIF to WordPress, or well any sort of image file, WordPress will upload the full size then resize to an array of different settings for thumbnails and medium sizes.  The issue is when it is an animated GIF the resized items are just a still of the first frame.  WordPress doesn’t have a GIF processor for rebuilding each frame at different sizes.

There is a plugin out there, it’s a bit outdated but might still do the trick.  If you aren’t planning on having hundreds of gifs slowing down your site then this code snippet will force all gifs to load their full size image when using the “Add Media” button.  You can then resize it with your mouse in place.

https://gist.github.com/ChrisFlannagan/10c87837150684fc0ab2fae0480deefb

Remove Catalog Visibility Hidden Products In WooCommerce From Search & WP REST API Results

Woo doesn’t filter out products with hidden catalog visibility outside of main shop loop. This is important to remember when using the REST API for front end display or general search results. This code snippet will keep them from showing outside of the admin.

https://gist.github.com/ChrisFlannagan/f79ab49491c2b85b0925c66a7fe971fd

Turn Off Localization Temporarily in WooCommerce

I’m working on a site that’s in Japanese.  It’s a huge WooCommerce shop and they have a lot of custom meta fields we built for the English version of things.  Customers have their first and last name in my account and also fields we made for English First Name and English Last Name.

On the Addresses endpoint of WooCommerce’s “My Account” section we wanted to display the names/addresses in both Japanese and English.  This seemed easy except the Japanese state name that’s generated by Woo was being translated in the ‘woocommerce’ text domain.  The work-around was to unload the text domain, reload the countries/states instance with the data, get our state then reload the text domain.  This snippet did the trick:

https://gist.github.com/ChrisFlannagan/423cb29c9ffe9a55baa2e955add81ba6

SNIPPET: Add an “Upgrade” Button To Item on Checkout in WooCommerce – Select Upgrade Product Per Product

This is JUST a proof of concept.  The code here is no where near ok for production.  I share as a snippet, use if/how you can.

https://gist.github.com/ChrisFlannagan/d7559c3682bc3db588cd9c6b70c01dec