【发布时间】:2021-06-30 18:31:20
【问题描述】:
我使用以下几行将Value 保存到数据库中。我对这段代码有一个问题,当我删除输入时它仍然保留它。删除它的唯一方法是将 (空格)作为输入。
$field_key_pills_1 = 'custom_text_field_category_pills';
if ( isset( $_POST[$field_key_pills_1] ) && ! empty( $_POST[$field_key_pills_1] ) ) {
$attribute_pills_1 = wc_get_product( $post_id );
$attribute_pills_1->update_meta_data( $field_key_pills_1, sanitize_text_field( $_POST[$field_key_pills_1] ) );
$attribute_pills_1->save();
} else {
$attribute_pills_1 = wc_get_product( $post_id );
$attribute_pills_1 = delete_post_meta( $post_id, 'custom_text_field_category_pills' );
}
请给我任何你认为可以解决这个问题的提示。
【问题讨论】:
标签: php wordpress woocommerce product custom-fields