Reputation: 2608
in Woocommerce (3.5.1 in my case), is it possible to remove all variation-specific images, so the image doesn't change when the user chooses a variation in the product page ?
I want this
instead of that
Upvotes: 2
Views: 2907
Reputation: 1
The SQLLite version worked for me perfectly. Thank you! Saved me the time of manually removing variation images from over 500 products! For anyone who wants to know, this is what I did.
Upvotes: 0
Reputation: 253814
You can bulk remove all product variation images bulk making a direct SQL query using phpMyAdmin for example (before backup your database):
UPDATE wp_postmeta as pm
JOIN wp_posts AS p ON pm.post_id = p.ID
SET pm.meta_value = ''
WHERE p.post_status = 'publish'
AND p.post_type = 'product_variation'
AND pm.meta_key = '_thumbnail_id'
Or you can use this light SQL query in a custom built-in function to remove all the variations images (or optionally only to a related parent variable product ID):
function remove_all_variations_images( $parent_id = 0 ){
global $wpdb;
$one_parent = $parent_id === 0 ? "" : "AND p.post_parent = $parent_id";
return $wpdb->query("
UPDATE {$wpdb->prefix}postmeta as pm
JOIN {$wpdb->prefix}posts AS p ON pm.post_id = p.ID
SET pm.meta_value = ''
WHERE p.post_status = 'publish'
AND p.post_type = 'product_variation'
AND pm.meta_key = '_thumbnail_id'
$one_parent
");
}
Code goes in function.php file of your active child theme (or active theme).
USAGE (before backup your database):
For all variations images in bulk you will add to your function.php file:
remove_all_variations_images();
Then save and browse any page of your site. Then remove it once finish.
For one specific variable product (let say variable product ID 72):
remove_all_variations_images(72);
Then save and browse any page of your site. Then remove it once finish.
Upvotes: 3