Automattic\WooCommerce\Internal\StockNotifications
Notification::get_product_permalink
Get product link.
Method of the class: Notification{}
No Hooks.
Returns
string.
Usage
$Notification = new Notification(); $Notification->get_product_permalink();
Notification::get_product_permalink() Notification::get product permalink code WC 11.2.2
public function get_product_permalink() {
$product = $this->get_product();
if ( ! $product ) {
return '';
}
$posted_attributes = $this->get_meta( 'posted_attributes' );
if ( ! $product instanceof \WC_Product_Variation || empty( $posted_attributes ) || ! is_array( $posted_attributes ) ) {
return $product->get_permalink();
}
// Posted attributes hold only the values chosen for "Any" attributes, so merge them over the variation's own attributes to build a complete link.
// Keys that no longer belong to the variation (e.g. a removed attribute) are dropped so they don't leak into the URL.
$variation_attributes = $product->get_variation_attributes();
$attributes = array_merge( $variation_attributes, array_intersect_key( $posted_attributes, $variation_attributes ) );
return $product->get_permalink( array( 'variation' => $attributes ) );
}