I am trying to remove an attribute row in a product attribute tab using code.

Woocommerce uses javascript to hide attribute row then uses ajax to save changes.

I need this row to be disappeared and removed after product page was refreshed.

Is there a function or a method to help me remove this row?



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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.