1

For each WooCommerce product, I want to use a unique background in the theme.

The simplest way I can think of doing this is by using a Custom Field for each WooCommerce product, with the value being an image ID or URI.

To make it more user friendly, is there anyway to add the custom field value via the WordPress native image uploader?

1
  • There are many plugins for adding rich interface custom fields to WordPress editor, both free and premium, check out official WordPress.org repository. Oct 3, 2017 at 17:49

1 Answer 1

0

So I'm not really sure exactly what you mean by adding a custom field value via the native image uploader. I would need better explanation to help troubleshoot that.

However, I've done something similar using Advanced Custom Fields to do what you're ultimately trying to achieve.

What I did was create an ACF field group and assign to woocommerce products post type. For your example, you create a field group with a single image field. This adds the custom field(s) to your WooCommerce product post type edit screen. Alternatively, you can create your custom fields and meta boxes manually. I just prefer ACF because it helps speed up development when budgeted time is a huge factor.

Then I use overriding templates to add whatever info is being entered into the ACF fields. You can learn more about how to create woocommerce overriding template at https://docs.woocommerce.com/document/template-structure/

Basically you create a folder in your theme's root, called 'woocommerce'. Then go to your woocommerce plugin (wp-content/plugins/woocommerce) and copy whatever file(s) inside the templates folder (wp-content/plugins/woocommerce/templates/) to your woocommerce folder in the theme root. You can then edit that template to your liking without worrying about the changes being lost after updating woocommerce.

Woocommerce also has a boat load of hooks you can use, so you may be able to use one of them depending on where and how you're trying to add this custom image to the product view. See woocommerce hooks at https://docs.woocommerce.com/wc-apidocs/hook-docs.html

Hope that helps.

1
  • Thanks, this is exactly what I was looking for. I didn't realise images could be setup through ACF.
    – illmasterj
    Oct 4, 2017 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.