Skip Navigation

[Resolved] Can't get Relationship for WooCommerce product

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by steveL-9 5 years, 2 months ago.

Author
Posts
#1380255

I am trying to:
I am overriding the WooCommerce Cart page.
I have a new Custom Post called "Style". A Style has a 1:N relationship with a Product. (One style will have 5-10 products. A product belongs to only one Style).

In the WooCommerce page I need to get the Style for the Product. The SLUG for the relationship is: style-product

Here's my code:
echo "<h1>PRODUCT ID IS " . $product_id . "</h1>";
$style_id = toolset_get_related_post( get_post($product_id), array( 'style-product', 'parent' ) );
echo "<h1>STYLE ID IS " . $style_id . "</h1>";

Link to a page where the issue can be seen:
hidden link

I expected to see:
The style for the product.

Instead, I got:
A zero for post id.

I also tried this:
$style_id = toolset_get_related_post( get_post($product_id), array( 'style', 'style-product' ) );

It did not work.

I can't find any documentation that shows how to get relationships for WooCommerce products.

#1380261

$style_id = toolset_get_related_post( get_post($product_id), 'style-product' );