choose frame for woocommerce image

Add a selection of Frames around product images in Woocommerce

I recently had a client who wanted a selection of frames to be able to be seen around a print in woocommerce.

See for example the result here

Appletreewick 2

I suppose one way would be to create variable products for each one and then an image including the frame for each but that would have taken ages. They will need to specify what frame they want somewhere else (like on Additional info on checkout page)

I added a bit of CSS and javascript.

The CSS (just gives Frame 1 as the default background image, and padding so it can show. Also removing a border around the image.)

.woocommerce-product-gallery__wrapper {
padding: 30px 30px 10px 30px !important;
.woocommerce-product-gallery__wrapper a {
border: 0px !important;
padding: 0px !important;

The Javascript. Added this in a widget that appears on every single product page. Modified by something I found here
Only very slight modifications from that code. I hope to tidy it up soon. Just very excited as a non-programmer at getting this to work!

I had to modify this as there is no ID for the image or wrapper for product image. So instead of targeting an ID I changed the code to target a CSS element so changed

var idCardBg = document.getElementById(“idhere”);


var idCardBg = document.getElementsByClassName(‘woocommerce-product-gallery__wrapper’)[0];

The Javascript
Placed in widget for all single product images.

<b>Select Frame</b>
<select onchange=”changeBgColor();” id=”select-idcard”>
<option id=”idcard-option1″ value=”blue”>Frame 1</option>
<option id=”idcard-option2″ value=”red”>Frame 2</option>
<option id=”idcard-option3″ value=”purple”>Frame 3</option>
<option id=”idcard-option4″ value=”green”>Frame 4</option>

var changeBgColor = function(){
var idCardBg = document.getElementsByClassName(‘woocommerce-product-gallery__wrapper’)[0]; = “url(‘’)”;
if(document.getElementById(“select-idcard”).value === “blue”){ = “url(‘’)”;
}else if(document.getElementById(“select-idcard”).value === “red”){ = “url(‘’)”;
}else if(document.getElementById(“select-idcard”).value === “purple”){ = “url(‘’)”;
}else if(document.getElementById(“select-idcard”).value === “green”){ = “url(‘’)”;
}else{ = “url(‘’)”;
} = document.getElementById(“select-idcard”).value;