-1

Recently, I installed a plugin that send the order details to WhatsApp, I did some changes on this to fit more for that I need, but now I have a problem and no ideia how to resolve, basically I need the attribute name and value after the user selected in this message as well I tried many ways and nothing work.

I tried this:

$product = $product->get_id();
$attr = $product->get_attribute( 'Tamanhos' ); // 'Tamanhos' is my attribute in admin panel
echo $attr;

Its show me my product ID perfectly but I got a error: "Fatal error: Uncaught Error: Call to a member function get_attribute() on int"

$product->get_id(); works good but the $product->get_attribute( 'tamanhos' ) have this error.

Someone know how how can I get the attribute name and value that user selected from a product?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • This question (error) is related to use the **WC_Product** method **get_attribute()**, but not *"how do I get the product attribute in WooCommerce"*. With `$product = $product->get_id()` you are replacing the product object with the product ID in the variable `$product`, and this is the main mistake, reason of your error: IN PHP you can not use a method on an integer (here the product ID). – LoicTheAztec Aug 06 '23 at 14:04
  • To resume, replace `$product = $product->get_id();`with `$product_id = $product->get_id();` and your code will work... – LoicTheAztec Aug 06 '23 at 14:17

0 Answers0