wc_fix_product_attachment_link( string $link, int $post_id )

Prevent product attachment links from breaking when using complex rewrite structures.


Description Description


Parameters Parameters

$link

(Required) Link.

$post_id

(Required) Post ID.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/wc-core-functions.php

function wc_fix_product_attachment_link( $link, $post_id ) {
	$parent_type = get_post_type( wp_get_post_parent_id( $post_id ) );
	if ( 'product' === $parent_type || 'product_variation' === $parent_type ) {
		$link = home_url( '/?attachment_id=' . $post_id );
	}
	return $link;
}

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.