Tag: php


WooCommerce: Use Product Images as Category Images

So, earlier this morning I found myself wishing that WooCommerce had the capability to use a product thumbnail when displaying a category link in situations where the category doesn’t have its own thumbnail defined.

I went on a bit of a hunt and found a couple of small plugins. One didn’t work at all, which I attribute mainly to it having not been updated for two years and much changing in both WordPress and WooCommerce since then, and another one that I found didn’t work until I made a couple of code changes – and had a couple of noteworthy problems;

  • it would only fetch product thumbnails from that immediate category – not delving deeper down into the category tree and fetch product thumbnails from child categories, and
  • it did no filtering for products that had no thumbnails set, so would in some cases return products that had no thumbnail

So, I’ve made my own. A zip download can be found below, you just need to drop the folder inside it into your wp-content/plugins folder and then activate the “WooCommerce Category Product Thumbnails” plugin.

I’m using WordPress 4.8.2 and WooCommerce 3.1.2 – please let me know in the comments if it doesn’t work on other versions.

Download the plugin (1.6KiB Zip)


getaddrinfo failed: A non-recoverable error occurred during a database lookup.

I faced an interesting (and by interesting, I mean incredibly frustrating) issue with a client yesterday, who had installed a PHP-based application of mine on their new Windows 7 laptop only to find that it was unable to connect to the MySQL database that powered it.

Testing showed that the connection was indeed failing, with this error being generated:

php_network_getaddresses: getaddrinfo failed: A non-recoverable error occurred during a database lookup.

I tried various things – forcing Windows to resolve localhost to (rather than ::1) in the hosts file, disabling IPv6 altogether and disabling the anti-virus package (AVG). I even tried installing fresh, bang-up-to-date copies of Apache, PHP and MySQL. Nothing worked – although the hosts file edit did at least change the error message, now it just said "Unknown error" instead – still very helpful.

Bashing my head against a brick wall, I decided to turn off services one by one until the problem changed. So I did, and eventually I got to the services running as part of the AVG CloudCare anti-virus package.

Switching the Cloud Care service off suddenly meant that any pages I tried to load in my web browser were replaced with a silly "Your Cloud Care service is not running!" error message.

I uninstalled AVG Anti-Virus completely (rather than just disabling it) and the problem immediately disappeared.

One to remember!