Some of my products have these weird variations with unspecified attributes (I am using Size and Color in my store). It looks like this:
So, if you would purchase a 85 B, Black variation of the product (ID 111224), in reality the order would contain the variation with unspecified attributes (ID 112392), because it is higher. It is a huge problem because those unspecified variations contain wrong SKUs and additional data.
I am using WP All Import for importing and updating products, I'm suspecting the plugin (or my settings) for this mess and I will look at it. However I have thousands of products in the store and deleting them manually is out of the question. Is there a way to delete variations that has at least one unspecified variation programatically?
I've tried to query such product variations using this tax_query:
'tax_query' = array(
'relation' => 'OR',
array(
'taxonomy' => 'pa_size',
'terms' => array(''),
'field' => 'slug',
'operator' => 'IN',
),
array(
'taxonomy' => 'pa_color',
'terms' => array(''),
'field' => 'slug',
'operator' => 'IN',
),
);
But the query doesn't return anything. It doesn't work when I try to pass empty string as a value inside 'term' array. I've also tried the '=' operator and empty string (not an array) as a value.
By the way, I've checked if those empty attributes really are empty strings and yes, they are. This code:
$product = wc_get_product(112392);
$atts = $product->get_attributes();
foreach($atts as $att) {
echo gettype($att) . ' : ' . $att . '<br>';
}
outputs this:
string :
string :
While for correct variations (e.g. 111224) it outputs:
string : 85-b
string : black
Any idea how could I get rid of them? I could just query all products variations, loop through them and delete all empty ones. Maybe repeat it couple of times (based on execution time) but it doesn't seem like a good solution, it is very performance expensive - the same problem might appear in the future as well and I would like a quick solution that would only query broken variations.
Thank you very much.