customization - How to remove product attribute row woocommerce using code

I am trying to remove an attribute row in a product attribute tab using code.Woocommerce uses javascript to hide attribu

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 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?

Share Improve this question asked Apr 16, 2019 at 19:59 MeMoMeMo 812 silver badges7 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 3

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745580998a4634254.html

相关推荐

  • customization - How to remove product attribute row woocommerce using code

    I am trying to remove an attribute row in a product attribute tab using code.Woocommerce uses javascript to hide attribu

    11小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信