WC_API_Products::delete_product_attribute_term( int $attribute_id, int $id )
Delete a product attribute term.
Description Description
Parameters Parameters
- $attribute_id
-
(Required) Attribute ID.
- $id
-
(Required) the product attribute ID.
Return Return
(array|WP_Error)
Source Source
File: includes/legacy/api/v3/class-wc-api-products.php
public function delete_product_attribute_term( $attribute_id, $id ) { global $wpdb; try { // Check permissions. if ( ! current_user_can( 'manage_product_terms' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_delete_product_attribute_term', __( 'You do not have permission to delete product attribute terms', '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 ); } $id = absint( $id ); $term = wp_delete_term( $id, $taxonomy ); if ( ! $term ) { throw new WC_API_Exception( 'woocommerce_api_cannot_delete_product_attribute_term', sprintf( __( 'This %s cannot be deleted', 'woocommerce' ), 'product_attribute_term' ), 500 ); } elseif ( is_wp_error( $term ) ) { throw new WC_API_Exception( 'woocommerce_api_cannot_delete_product_attribute_term', $term->get_error_message(), 400 ); } do_action( 'woocommerce_api_delete_product_attribute_term', $id, $this ); return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'product_attribute' ) ); } 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. |