-2

So i am trying to make a web shop plugin that will add all product, it will get them from an api for products i get from a supplier. Now i am trying to make an attribute programmatically with php but i cant find how i have tried a lot of code from other people but its outdated or i cant get it to work, i just want whenever I press a button that the attribute will be create just an attribute nothing more.

I have tried Create new product attribute programmatically in Woocommerce answer code (and more…).

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • 1
    Sorry but the answer code that you mentioned is not outdated and still works in last WooCommerce version… Also you are expected to provide your own real code attempt in your question, explaining in details what doesn't work… Please note that StackOverFlow is not a free coding service. – LoicTheAztec Oct 15 '20 at 15:03

1 Answers1

0

Is that the exact code you try to run?

The action "init" is run in every WordPress request on start up.
There is no connection to a button press.

Your parameter "$label_name" in function create_product_attribute($label_name) is not going anywhere.

The rest of your code looks like it could lead you to you goal. But the code is initiated in a way that can to bring you closer to the goal.

You want to add a certain attribute manually to certain products?

Or press one button once and have the attribute on every product?

You could have an admin page with a button that sets a URL parameter - if that parameter is set, do some action.

ibes
  • 77
  • 5