wc_update_attribute()
Update an attribute.
For available args see wc_create_attribute().
Хуков нет.
Возвращает
int|WP_Error
.
Использование
wc_update_attribute( $id, $args );
- $id(int) (обязательный)
- Attribute ID.
- $args(массив) (обязательный)
- Attribute arguments.
Список изменений
С версии 3.2.0 | Введена. |
Код wc_update_attribute() wc update attribute WC 9.3.3
function wc_update_attribute( $id, $args ) { global $wpdb; $attribute = wc_get_attribute( $id ); $args['id'] = $attribute ? $attribute->id : 0; // When updating an existing attribute, populate any undefined args with the existing value. // This prevents those values from being reset to their respective defaults. if ( $args['id'] ) { $args['has_archives'] = $args['has_archives'] ?? $attribute->has_archives; $args['name'] = $args['name'] ?? $attribute->name; $args['order_by'] = $args['order_by'] ?? $attribute->order_by; $args['slug'] = $args['slug'] ?? $attribute->slug; $args['type'] = $args['type'] ?? $attribute->type; } if ( $args['id'] && empty( $args['name'] ) ) { $args['name'] = $attribute->name; } $args['old_slug'] = $wpdb->get_var( $wpdb->prepare( " SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = %d ", $args['id'] ) ); return wc_create_attribute( $args ); }