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
- how to use wc_create_order with subscription product
- Add custom variable to cart content [closed]
- WooCommerce changes lost password reset link
- Default woocommerce placeholder image
- WooCommerce: Add New Report Tab
- How to add Woocomrce cart page shipping calculator to my country state list
- Custom Woocommerce image size [closed]
- How to combine tax_query and date_query in WordPress
- Migrate WooCommerce Orders [closed]
- WooCommerce Subscriptions: Show monthly Price for annual Product
- How to add multiple product gallery images from front-end
- Hide income in Woocomercer [closed]
- Disabling the free shipping method when the cart has product/s which assigned a certain shipping class [closed]
- woocommerce_email_subject_customer_completed_order
- is_shop, is_home, is_front_page doesn’t work for woocommerce
- WooCommerce: The model of e-mail is displaying only the html, not css [closed]
- How to show loading spinner after click on add to cart button [closed]
- Woocommerce – Show random product thumbnail from specific product category
- How to add a greeting message upon logging into WordPress for certain user role
- Modify some CSS with functions if (function_exists
- Limit total quantity of products in WooCommerce group product
- WordPress keeps moving my widgets to other widget areas
- Woo-commerce Checkout Summarized in Pop-up Card Entry Only
- Display Message if woocommerce coupon is not applicable to some items in the cart
- How do I add an extra field to comment form above the submit button?
- woocommerce email template detect email recipient
- WooCommerce – buying as well as selling
- How do I hide ‘out of stock’ products in the admin ‘product’ page?
- WordPress and WooCommerce – How many products are too many? [closed]
- Add custom field to Woocommerce add new attribute / edit page
- woocommerce axios react
- JWT on Woocommerce cannot work with “Customer” role user
- Woocommerce – Add HTML around Product description [closed]
- relocate woocommerce notices/messages on Cart page
- Woocommerce emails from gmail not being sent
- lost password link not working for my site
- How to give each category name its own ACF background color?
- WooCommerce 4: Gallery size is too large in mobile
- WooCommerce event works in jQuery but not in JavaScript
- Filter default_content only for products
- Get woocommerce coupon code
- Remove Visual Editor and P tags from WooCommerce Taxonomy Descriptions [closed]
- Custom tax_query filter not working for Woocommerce product categories
- Woocommerce Remove Tax by Product Type
- get_posts $args won’t accept array as one of the criteria?
- Adding additional text under the price via product page
- Display WooCommerce product category on shop page (on every product)
- Add custom parameters to Woocommerce add to cart link
- Multisite login – registration is duplicated
- WooCommerce variable product can not add to cart using ajax after updating latest version of WooCommerce
- Create a Search Form that only Searches with WooCommerce Sale Products
- Update WooCommerce Sale Price & Date Based On Attribute Value
- Logo showing on some page but not on product categories pages
- Categories on attribute archive pages
- How to solve `Error getting remote image` in woocommerce rest api script?
- Woocommerce Product Variation – Add Price Logic
- Display related product categories by subcategory
- Woocommerce Multisite global search how to mod ajax function?
- How to let users create lists of woocommerce products?
- How to force Woocommerce to deliver the product to the paypal adress which was used?
- Order again Woocommerce inside View Order
- Photo cover in WooCommerce
- How to vary WooCommerce product prices based on order dates
- How to save one API response to WooCommerce order meta data
- WooCommerce and ACF: How to Redirect Upon Add to Cart – Partially Working Example
- Woocommerce: Search by custom attribute
- How to change user role after login?
- Set Post Thumbnail to external URL
- Custom theme woocommerce product detail page template not working
- Increase the download speed of a large number of variations in WooCommerce
- remove add to cart for free (0 $) product woocommerce
- merge tabs in woocommerce
- WooCommerce: Adding a setup fee to certain products
- Removing shipping for one product with coupon
- Awesome Support Custom Field for show Woocommerce orders
- How to make a custom redirect in WooCommerce?
- Firstname and lastname greyout or hidden Billing details at next checkout like username is hidden [closed]
- How to use woo commerce login to authenticate code php pages?
- Site with WooCommerce section moved to HTTPS – all pages except home and main store are 404s
- Multiple quantities with options
- how to add custom reviews button in woocommerce order complete generated mail
- Not all strings are translated
- Woocommerce – get product in category with specific attribute
- Woocommerce make appear when items added to cart
- Testimonials/Reviews for Products
- How to display Woocommerce catagories
- add custom menu in woocommerce dashboard [closed]
- Updating order meta to have a meta entry from an item in the order
- registration_errors not working
- Translate Woocommerce tab
- Woocommerce -> gallery images per variation without a plugin? [closed]
- Why is my WordPress admin not working
- Create bookings after subscription renewal
- Change variants URL
- Use a woocommerce hook to create a table and populate it with a query