WC_API_Products::delete_product_tag()
Delete a product tag.
Метод класса: WC_API_Products{}
Хуки из метода
Возвращает
Массив|WP_Error
. Success message if succeed, otherwise WP_Error will be returned
Использование
$WC_API_Products = new WC_API_Products(); $WC_API_Products->delete_product_tag( $id );
- $id(int) (обязательный)
- Product tag term ID
Список изменений
С версии 2.5.0 | Введена. |
Код WC_API_Products::delete_product_tag() WC API Products::delete product tag WC 8.1.1
public function delete_product_tag( $id ) { try { // Check permissions if ( ! current_user_can( 'manage_product_terms' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_delete_product_tag', __( 'You do not have permission to delete product tag', 'woocommerce' ), 401 ); } $id = absint( $id ); $deleted = wp_delete_term( $id, 'product_tag' ); if ( ! $deleted || is_wp_error( $deleted ) ) { throw new WC_API_Exception( 'woocommerce_api_cannot_delete_product_tag', __( 'Could not delete the tag', 'woocommerce' ), 401 ); } do_action( 'woocommerce_api_delete_product_tag', $id, $this ); return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'product_tag' ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }