I have a two pronged problem with the custom application of an existing WooCommerce plugin (the Product Add-Ons extension).
I have WooCommerce/WordPress running perfectly fine and am using the Product Add-Ons extension to capture registration information for the customer's child as part of the order process.
There are 56 potential inputs (not all mandatory, so some can remain null) that a customer fills out regarding their child. This part of my process works fine.
I also have a registrant database (of youth players) that is part of a custom built league management system. That database table has 57 columns in each row.
The first problem I'm having is getting all of the data from the first table copied over to the second table and I think I understand why, I just don't know how to solve it.
Both tables exist within the same database.
The first table is called woocommerce_order_itemmeta and it's structure is as follows:
meta_id,
order_item_id,
meta_key,
meta_value
The first two columns do not need to be copied over as the information they contain ONLY relates to WooCommerce itself.
The following two columns work as follows; when I create an input field as a product add-on and a customer completes an order the meta_key field contains which input it is and the meta_value contains the information the customer entered.
For example:
**meta_key** = Lastname, **meta_value** = Smith,
**meta_key** = Firstname, **meta_value** = John,
Each order could have 56 of these associated with it.
Now, once an order is flagged as completed within WooCommerce, I need to it execute a transfer/copying of the data for that specific order into a second database with a completely different structure.
The second table is signUps and it's structure is a lot more straight forward:
num,
teamRole,
lName,
fName,
mName,
guardianMother,
guardianMphone,
guardianFather,
guardianFphone
etc... for a total of 57 rows. the num column is an auto-increment integer and can be skipped.
The problem I'm having is that the columns are mismatched 4 to 57 and, from what I can gather, it's also a bit more difficult because I have to select the **meta_value** WHERE the **meta_key** is *X*
and do this for each entry, to then copy the information into a more straightforward table.
I suspect that if I had a clearer structure and could just grab the value of "Lastname,Firstname,Middlename,etc" without first having to identify it as a KEY, that it would be easy to then just insert it into "lName,fName,mname,etc".
So far, I can get the following query working in phpMyAdmin:
INSERT INTO `signUps`(lName) SELECT `meta_value` FROM `woocommerce_order_itemmeta` WHERE `meta_key` = 'Lastname';
The problem kicks in when I try to find ways to add a second value to the query.
What I basically need is a way to get all of the data collected to copy to the appropriate columns in the second table.
The second problem I'm having is that we can't get anything at all to fire when I use the woocommerce_order_status_completed action hook the way the documentation says I should.
add_action( 'woocommerce_order_status_completed', 'register_player' );
The only additional caveat is that I can't change the structure of either table - they are the way they are because so many other, unrelated functions, rely heavily on both of them. (It's actually sort of frustrating.) I'd love to just use the one table instead of duplicating the information, but then I'd be re-writing someone else's entire league management application and I'm lacking in both the time and the expertise to do so.
Any solutions would be greatly appreciated. Thanks guys.