mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-29 11:32:21 +08:00
https://businessbloomer.com/woocommerce-switch-image-background-on-color-variation-selection/
21 lines
732 B
Text
21 lines
732 B
Text
add_action( 'woocommerce_after_variations_form', 'wc_switch_image_background_variable_colors' );
|
|
|
|
function wc_switch_image_background_variable_colors() {
|
|
|
|
wc_enqueue_js( "
|
|
|
|
$('input.variation_id').change(function(){
|
|
if('' != $('input.variation_id').val()) {
|
|
if($('#pa_color').val() =='red'){
|
|
$('.woocommerce-product-gallery figure').css('background-color', 'red');
|
|
} else if($('#pa_color').val() =='yellow'){
|
|
$('.woocommerce-product-gallery figure').css('background-color', 'yellow');
|
|
}
|
|
} else {
|
|
$('.woocommerce-product-gallery figure').css('background-color', 'transparent');
|
|
}
|
|
});
|
|
|
|
");
|
|
|
|
}
|