WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

Pagination::add_headers() public WC 1.0

Add pagination headers to a response object.

{} It's a method of the class: Pagination{}

No Hooks.

Return

\WP_REST_Response.

Usage

$Pagination = new Pagination();
$Pagination->add_headers( $response, $request, $total_items, $total_pages );
$response(\WP_REST_Response) (required)
Reference to the response object.
$request(\WP_REST_Request) (required)
The request object.
$total_items(int) (required)
Total items found.
$total_pages(int) (required)
Total pages found.

Code of Pagination::add_headers() WC 5.7.1

public function add_headers( $response, $request, $total_items, $total_pages ) {
	$response->header( 'X-WP-Total', $total_items );
	$response->header( 'X-WP-TotalPages', $total_pages );

	$current_page = $this->get_current_page( $request );
	$link_base    = $this->get_link_base( $request );

	if ( $current_page > 1 ) {
		$previous_page = $current_page - 1;
		if ( $previous_page > $total_pages ) {
			$previous_page = $total_pages;
		}
		$this->add_page_link( $response, 'prev', $previous_page, $link_base );
	}

	if ( $total_pages > $current_page ) {
		$this->add_page_link( $response, 'next', ( $current_page + 1 ), $link_base );
	}

	return $response;
}