HasteDesign / Registrations-for-WooCommerce

Add a registration product type to your WooCommerce installation.
GNU General Public License v2.0
38 stars 16 forks source link

Add variations programatically? #27

Closed ajlowndes closed 5 years ago

ajlowndes commented 6 years ago

I have been browsing the code quite a lot lately, trying to figure out what I need to add to the database to add a variation to an existing product, programatically. I have tutorials on how to do it with normal woocommerce products - but unsure how they apply to this custom product type... Am I correct in thinking that i would simply add, for example {"type":"range","dates":["2018-03-10","2018-03-11"]} to the "dates" database entry under a new variation id? OR, is there a ready-made hook reference already in the code? If not, where would it be put?

ajlowndes commented 6 years ago

https://code.tutsplus.com/tutorials/writing-extensible-plugins-with-actions-and-filters--wp-26759 for a tutorial on adding hooks to custom plugins... maybe you've already done this though? i can't really tell....

allysonsouza commented 6 years ago

Hi @ajlowndes,

I guess you just need to add a new variation, to a product of type registrations, with the format {"type":"range","dates":["2018-03-10","2018-03-11"]}. It's not good, but it's the way it's workin for now

ajlowndes commented 4 years ago

Okay tackling this again after a long (long) hiatus. Struggling to add a new variation unless I somehow add the date attribute to the existing list first. Any idea how this is accomplished from the api end? Thx