WC_Post_Data::variation_post_link( string $permalink, WP_Post $post )

Link to parent products when getting permalink for variation.


Description Description


Parameters Parameters

$permalink

(Required) Permalink.

$post

(Required) Post data.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class-wc-post-data.php

	public static function variation_post_link( $permalink, $post ) {
		if ( isset( $post->ID, $post->post_type ) && 'product_variation' === $post->post_type ) {
			$variation = wc_get_product( $post->ID );

			if ( $variation && $variation->get_parent_id() ) {
				return $variation->get_permalink();
			}
		}
		return $permalink;
	}


Top ↑

User Contributed Notes User Contributed Notes

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