With woocommerce 2.3 there was post_parent for single products what was the part of grouped product. So it was possible to link them by:
function parent_permalink_button() {
global $post;
if( $post->post_parent != 0 ){
$permalink = get_permalink($post->post_parent);
echo '<a class="button" href="'.$permalink.'">Link to Parent</a>';
}
}
with woocommerce 3.0.0 update situation changed. Actually it is opposite now. Grouped product has its _children.
How can I create the link from single product to its grouped? It can be a part of more grouped product so there can be multiple links (but it is not the case of my shop)
Thanks Michal
It's possible to build that function for WooCommerce 3+ this way:
(with an optional
$post_id
argument)Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works in WooCommerce 3+
USAGE: (2 cases)
1) Without using the optional argument
$post_id
for example directly in the product templates:2) Using the function everywhere, defining the it's argument
$post_id
: