WC_API_Products::edit_product_attribute_term( int $attribute_id, int $id, array $data )
Edit a product attribute term.
Description Description
Parameters Parameters
- $attribute_id
-
(Required) Attribute ID.
- $id
-
(Required) the attribute ID.
- $data
-
(Required)
Return Return
(array|WP_Error)
Source Source
File: includes/legacy/api/v3/class-wc-api-products.php
public function edit_product_attribute_term( $attribute_id, $id, $data ) { global $wpdb; try { if ( ! isset( $data['product_attribute_term'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_product_attribute_term_data', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'product_attribute_term' ), 400 ); } $id = absint( $id ); $data = $data['product_attribute_term']; // Check permissions. if ( ! current_user_can( 'manage_product_terms' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_edit_product_attribute', __( 'You do not have permission to edit product attributes', 'woocommerce' ), 401 ); } $taxonomy = wc_attribute_taxonomy_name_by_id( $attribute_id ); if ( ! $taxonomy ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_attribute_id', __( 'A product attribute with the provided ID could not be found', 'woocommerce' ), 404 ); } $data = apply_filters( 'woocommerce_api_edit_product_attribute_term_data', $data, $this ); $args = array(); // Update name. if ( isset( $data['name'] ) ) { $args['name'] = wc_clean( wp_unslash( $data['name'] ) ); } // Update slug. if ( isset( $data['slug'] ) ) { $args['slug'] = sanitize_title( wp_unslash( $data['slug'] ) ); } $term = wp_update_term( $id, $taxonomy, $args ); if ( is_wp_error( $term ) ) { throw new WC_API_Exception( 'woocommerce_api_cannot_edit_product_attribute_term', $term->get_error_message(), 400 ); } do_action( 'woocommerce_api_edit_product_attribute_term', $id, $data ); return $this->get_product_attribute_term( $attribute_id, $id ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }
Changelog Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |