I have found a solution after some digging in database:
$product_attributes = get_post_meta( $product->id , '_product_attributes' );
$temp_product_attributes = [];
foreach($product_attributes as $product_attribute) {
foreach($product_attribute as $pt_k => $pt_v) {
if ($pt_k !== $attribute_name) {
$temp_product_attributes[$pt_k] = $pt_v;
}
}
}
update_post_meta( get_the_ID(), '_product_attributes', $temp_product_attributes);
First we need to get all of product attributes
then we traverse the array and remove the attribute we don’t want any more (by the way I have store unwanted attribute in $attribute_name
).
At the end we save the post meta with new product attributes without the one we wanted to eliminate.
$temp_product_attributes
is for saving the attributes we already have.