Google products feed and get main product id

  • Posts: 1119
  • Thank you received: 114
6 years 11 months ago #269309

Hi,

I am using google products plugin to feed facebook catalog. All works fine with only 1 issue.

As plugin do not support variants i need to get main product id.

Using this code gives id per product variant:

$ids = array();
foreach($this->order->products as $product){
$ids[]=$product->product_id;
}
echo implode(',',$ids);

How can i echo main product id?

facebook looks like this:

3 items purchased

content_ids: ["5226,5219,5224"]

5226 and 5224 are variants of same product.

I hope you see the issue.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
6 years 11 months ago #269329

Hi,

This code will get the id of the main product based on the id of the variant.

$class = hikashop_get('class.product');
$productData = $class->get($product->product_id);
echo $productData->product_parent_id;

The following user(s) said Thank You: kyratn

Please Log in or Create an account to join the conversation.

  • Posts: 1119
  • Thank you received: 114
6 years 11 months ago #269366

Hi,

Thank you. I see my mistake.
For some reason i was looking for"main" product id and not parent.

Thanks again and have a great weekend!

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum