Automattic\WooCommerce\Internal\ProductDownloads

DownloadableFileAttachments::handle_attachment_link │ public │ WC 1.0

Use an ID-only link for downloadable product files.

The usual link includes the attachment's slug, which is based on the original file name. Canonical and other redirects that point to the attachment then land on a URL that reveals nothing and shows a 404.

Method of the class: DownloadableFileAttachments{}

No Hooks.

Returns

string|mixed.

Usage

$DownloadableFileAttachments = new DownloadableFileAttachments();
$DownloadableFileAttachments->handle_attachment_link( $link, $attachment_id );
$link(string|mixed) (required)
Attachment link.
$attachment_id(int|mixed) (required)
Attachment ID.

DownloadableFileAttachments::handle_attachment_link() code WC 11.3.0

public function handle_attachment_link( $link, $attachment_id ) {
	$attachment_id = absint( $attachment_id );

	return $this->is_hidden_attachment( $attachment_id ) ? add_query_arg( 'attachment_id', $attachment_id, home_url( '/' ) ) : $link;
}