I’ve managed to write an SQL query that would get all product variation IDs that do not have both size and color set up (not present in the wp_postmeta table). After that I just need to loop through these IDs and delete those variations using wp_delete_post. This is the query:
SELECT p.ID
FROM wp_posts p
LEFT JOIN wp_postmeta pm
ON p.ID = pm.post_id
WHERE p.post_type="product_variation"
AND (pm.post_id NOT IN (SELECT post_id FROM wp_postmeta WHERE meta_key = 'attribute_pa_size' OR meta_key = 'attribute_pa_color'))
GROUP BY ID
Works well for my case. I was originaly asking about variations that has at least one attribute unspecified, but turned out that wouldn’t be the solution, I had to look for variations with boths attributes empty.
Related Posts:
- Hidden woocommerce products still showing up in search results [closed]
- Woocommerce change tax rate programmaticly
- Tax Query for custom Taxonomy field
- How to exclude a taxonomy from shop & search page wooCommerce?
- Set both meta_query and tax_query using wp_query->set
- Get the product list of a given Category ID
- get woocommerce My account page link
- Correct function to get the user’s latest Woocommerce Subscription?
- Move payment options at checkout in WooCommerce [closed]
- Is it safe to delete from db orphaned posts i.e. whose post_parent no longer exists?
- WooCommerce – Hook after Loading Variation in Admin Edit page?
- WooCommerce conditional meta query
- Add a custom button with custom link after add to cart for every product
- Redirect woocommerce single-product page
- New endpoint in my account gives 404 Error Woocommerce 3.6.5 and WP 5.2.2
- Username field is not shown in Woocommerce’s registration contact form
- Woocommerce Membership Expiry Date
- How to echo billing phone number under My Account in Woocommerce? [closed]
- Unknow php file in wordpress core [closed]
- woocommerce_get_price filter hook not working for product variation price
- Woocommerce SKU on ALL products page [closed]
- Stop WooCommerce from updating user/user meta after checkout
- Redirect user to cart page when add to cart button is clicked
- Woo API REST : product variation price is read-only?
- Get rid of product images mobile swipe functionality from WooCommerce single product [closed]
- Disable Local Attributes woo commerce
- Problems with varibel price [closed]
- Custom Admin Email Subject for Woocommerce (3.8.0) Orders
- Woocommerce custom endpoints
- Replacing products on Woocommerce Product Category with Search Results from SearchWP [closed]
- Creating custom permalink tags for WooCommerce
- Add Custom Slug Tags Per Page
- How to override Woocommerce functionality in Reports section?
- how can use woocommerce add to cart popup?
- Do I need a different product type for WooCommerce [closed]
- Hide account tab to certain users
- How to Update the Order-Items While Editing an Order on the WooCommerce Admin Order Screen [closed]
- I want to run a script only once on a ‘thank you’ page
- search customers in front end by billing data
- Is it safe to have 2 mysql users?
- update_post_meta not work [closed]
- How to set a default value in a meta box
- Can I have one picture for all sizes in a product with Woocommerce?
- Adjust Price Display for Variable Product in Woocommerce [closed]
- Woocommerce password Reset
- Unable to pull in custom product attribute in shortcode [closed]
- Woocommerce redirect “add to cart” button to a contact form with product information to get a inquiry
- How to remove WooCommerce Plugin some specific features [closed]
- How to remove product attribute row woocommerce using code
- override the default WooCommerce products search form
- How can I override wp_price woocommerce function in my theme
- Woocommerce : read [max_qty] using backorder
- Woocommerce Product permalinks “product” word is not working
- Conditionally run function based on custom meta value?
- Woocommerce checkout required field error
- Setting a default variation for each product on the child theme functions.php file
- Issue with WordPress customize
- Group product by Instance ID
- WordPress woocommerce new order email not working
- WooCommerce add extra price to products by each category
- HTTP API CALLS issue on Woocommerce WordPress
- Sort products by Sale price and stock status
- Pagination in woocommerce – Limiting page-numbers
- Syncing WP Database Changes Between Environments: How To Handle Merging w/o touching database
- Show shipping class in admin order list
- One Time Access URL after purchasing subscription
- How to fetch WooCommerce products with 50% discount?
- Woocommerce digital download not working – database error Cannot add or update a child row: a foreign key constraint fails [closed]
- when product out of stock single page show button notify woo-commerce
- WooCommerce , Auto cancel orders status from processing after X days
- Change WooCommerce Word “Product” to Another Word
- How does a WooCommerce site integrate with the existing real world customer members?
- How can I send information when a order is completed to my own POS?
- How can i add product Accessories from front-end using custom php form?
- How to save order item custom attributes save into custom table
- Manually create an order with a product ID woocommerce
- How to filter result set in custom metaboxes?
- How to change lost password email text using custom plugin wordpress?
- wc_mail in foreach loop is sending only the first email
- WooCommerce subscriptions give option of manual renewal on checkout [closed]
- How to hide / remove duplicated Woocommerce products from Shop page
- How to add product variations for large number of products in WooCommerce?
- Change order status after checkout
- Is it safe to update an old site after backing it up and activating a child theme?
- Disable Woocommerce main shop page, but not the product category archive pages
- Woocommerce Languages Files
- How to store ACF from product in user_meta?
- Changing second user role while updating/downgrading membership level – s2member [closed]
- How to edit the header banner in the search page in woocommerce?
- Trying to link to a custom css file in a new folder
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- How to edit schema.org markup of WooCommerce?
- How to change redirect code? [duplicate]
- Adding a column to woocomerce admin order page that can be sorted
- WordPress error
- Hide price, “add to cart” button and show message “Please log in to shop” [closed]
- Auto generating API keys using the Application Authentication Endpoint [closed]
- Is there a way to conditionally check if i’m on product variation page url like mydomain.com/myproduct?attribute_pa_color=red
- Account Status/Login on Main Menu with Avatar Pictures
- Custom plugin development with paypal subscription method