admin管理员组文章数量:1023648
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 01 Answer
Reset to default 3I 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.
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 01 Answer
Reset to default 3I 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.
本文标签: customizationHow to remove product attribute row woocommerce using code
版权声明:本文标题:customization - How to remove product attribute row woocommerce using code 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745580996a2157309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论