I am developing a site that uses WooCommerce & WordPress to show a fair amount (10,000+) products, and can't accommodate the size of all the images for the products. So, I'm leaving the images on their CDN, and making all the image attachments references to the external URLs.
This required a bit of hacking, as WooCommerce/WordPress will try to take the images and upload them and set the attachment URL to a local relative path (eg,
2018/02/), and then when the images are called later on the site, the
wp_get_attachment_url will add the uploads directory to the base image, giving something like
Basically what I've done to make this all pan out is
- Stop WordPress from running the
wp_generate_attachment_metadataby setting it to
return trueas soon as the function is called, which prevents the image from being downloaded and from being copied into the uploads directory.
- Upload the products from a CSV
- Run a MySQL query to copy the woocommerce source image URL on to the attachment location
wp_get_attachment_urlto not append the uploads directory to attachment images
Essentially, a couple of 1 line changes to the WordPress core. Which is bad, because any time in the future when the site updates it'll just bork the changes.
Is there a healthier way to approach this?