WC_API_Products::edit_product_tag()publicWC 2.5.0

Edit a product tag.

Метод класса: WC_API_Products{}

Возвращает

Массив|WP_Error. Product tag if succeed, otherwise WP_Error will be returned

Использование

$WC_API_Products = new WC_API_Products();
$WC_API_Products->edit_product_tag( $id, $data );
$id(int) (обязательный)
Product tag term ID
$data(массив) (обязательный)
Posted data

Список изменений

С версии 2.5.0 Введена.

Код WC_API_Products::edit_product_tag() WC 8.7.0

public function edit_product_tag( $id, $data ) {
	try {
		if ( ! isset( $data['product_tag'] ) ) {
			throw new WC_API_Exception( 'woocommerce_api_missing_product_tag', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'product_tag' ), 400 );
		}

		$id   = absint( $id );
		$data = $data['product_tag'];

		// Check permissions.
		if ( ! current_user_can( 'manage_product_terms' ) ) {
			throw new WC_API_Exception( 'woocommerce_api_user_cannot_edit_product_tag', __( 'You do not have permission to edit product tags', 'woocommerce' ), 401 );
		}

		$data = apply_filters( 'woocommerce_api_edit_product_tag_data', $data, $this );
		$tag  = $this->get_product_tag( $id );

		if ( is_wp_error( $tag ) ) {
			return $tag;
		}

		$update = wp_update_term( $id, 'product_tag', $data );
		if ( is_wp_error( $update ) ) {
			throw new WC_API_Exception( 'woocommerce_api_cannot_edit_product_tag', __( 'Could not edit the tag', 'woocommerce' ), 400 );
		}

		do_action( 'woocommerce_api_edit_product_tag', $id, $data );

		return $this->get_product_tag( $id );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}