how to display variables in product id in product page

  • Posts: 20
  • Thank you received: 0
2 years 6 months ago #336320

-- HikaShop version -- : 4.4.4
-- Joomla version -- : 4.0.3
-- PHP version -- : 7.4
-- Error-message(debug-mod must be tuned on) -- : how to display variables in product id in product page

hiI was able to display the product ID on the product page via the following code. But I want for products that have variety. Display the ID of each variety of product.

echo $this->element->product_id;

Thank you for guiding me.

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

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
2 years 6 months ago #336326

Hi,

Are you talking about variants ?
The variants data is available in $this->element->variants
This is an array of variant objects.
So you can do it like that:

foreach($this->element->variants as $variant) {
 echo $variant->product_id;
}

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

  • Posts: 20
  • Thank you received: 0
2 years 6 months ago #336330

hi
thank you for reply.
I want the ID of each variant of the product to be displayed by selecting the desired variant. With the following code, all product IDs of all variants are displayed together!
For example, I have a product with the ID 650 and the ID of its variants, respectively, equal to 651/652/653/654, now with the code you gave, the following number is displayed in one place.
650651652653654
Do you understand what I mean?
I want product id (variant ) for each variants to be displayed dynamically.
thank you.

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

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
2 years 6 months ago #336331

Hi,

Well, then you can add your code in product / show.php via the menu Display>Views.
For example, if you want to add the product_id of the current variant just after the product name on the product page, you can change the line:
echo $variant->product_name;
to:
echo $variant->product_name. ' ' . $variant->product_id;

When you select a variant, the name will change and the id displayed there too.

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

  • Posts: 20
  • Thank you received: 0
2 years 6 months ago #336342

Hi
I added the following code in the view show_tabular.php but it does not show anything!
<?php echo $variant->product_name. ' ' . $variant->product_id; ?>

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

  • Posts: 81513
  • Thank you received: 13068
  • MODERATOR
2 years 6 months ago #336350

Hi,

That's normal. I talked about code to replace, not add, and I talked about product / show.php not product / show_tabular.php
Please follow the instructions.

The following user(s) said Thank You: farzadfarzad

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

Time to create page: 0.072 seconds
Powered by Kunena Forum