How to get WooCommerce cart id? - wordpress

I have developed a Wordpress plugin which adds products programmatically using this code:
WC()->cart->empty_cart();
foreach ($productos as $producto) {
WC()->cart->add_to_cart($producto->post_id, $cantidad);
}
After I add products to cart I need to save the cart id, because after the user proceed to checkout and do the payment, I need to save the order id together with the cart id in a custom database table.
Any help, please?
On the other hand, in what database table are the carts and the orders stored?
EDIT (more details)
The actual problem is this. My plugin allows the customer to do some choices before proceeding with the purchase. All those choices are stored in a custom database table I created together with the default WordPress tables.
When the payment was made, I need to save the order id in that custom table in the same record of those choices, so that, in a later time, I will be able to know which choices were set for determined purchase.
Thinking in other way to accomplish this. The table record of choices has an ID (the primary key). Is it possible to save that ID together with the order? If that is possible, that way I can do the match between the order and the choices.

Related

Get an latest order notes both customer and private and store in seperate custom field Woocommerce Order

I want to get an latest order notes both customer and private in two separate meta keys in the order admin console. Basically below are the things i need which i can put in functions.php
Add two customer fields one for private note and customer note. This can be custom field (meta_key) for order page.
This two custom field can be displayed in the right side on the admin order page as metabox on right hand side
These two custom field will contain only the last order note (private or customer) and value will be stored in the meta_value of the key for orders.
Please help i want to use these meta_keys as variables to send the SMS.
Regards
Vishal Sanghi

Getting Woocommerce cart ID before checkout

I am building a PHP $_SESSION array as a user goes thru the shopping process, collecting data about their actions. I want to insert the current cart ID or order ID into the session array so I can tie the two together.
How do I get the cart ID or order iD before checkout, like from inside of woocommerce_ajax_add_to_cart() or something, so as soon as the first product is added to the cart, it also adds the cart ID to the session?
TL;DR how do I get the woocommerce cart ID after the first product is added, and use that to get the final order ID after payment?

Including Inventory Number in global search

I actually can't find any option how can i add this Inventory Number entries (subtab on item records) in global search. It would save me a lot of time if this field can be searchable under global netsuite's search which is located in header of every single page.
Is something like this possible? I asked their support and they are navigating me to their support documentation which is not that rich when this question is placed.
Please see screenshot of what i want to include in my global search
There isn't a way that I know of to make default fields accessible to the global search but you can make custom fields accessible.
You should be able to make a custom field that stores the value of the Inventory Number. Custom fields have a checkbox of "Global Search". The field must store the value so you will need to make sure that it updates if the Inventory Number ever updates (workflow/suitescript).
From NetSuite article 8403 titled "Including Custom Fields in Global Search":
To index a custom field to be included in global search, a user with
permission to edit or create custom fields must check the Global
Search box on the custom field record. By default, the Available for
Global Search box is not checked for preexisting or new custom fields.
Global search indexing is available for the following data types, when
the Store Value preference is enabled:
Currency
Decimal Number
Email Address
Free-Form Text
Help
Hyperlink
Inline HTML
Integer Number
Percent
Phone Number
Text Area
You cannot index a custom field for global search if None is
selected for any Level for Search/Reporting option on the Access
subtab of the custom field record.

What is the disadvantage of adding custom field in post table in wordpress

I am a naive developer and just learning wordpress. I am going to use a custom post type in wordpress and having a question on whether I shall add some more custom fields in post table or I shall use post_meta table. People have been suggesting to use post_meta giving reference to wordpress design and upgrade issue but wouldn't performance be impacted if I add fields to post_meta when records grow in this table as it will be vertical growth.
Let's take an example that I am inserting 2 records in post table and I have 3 custom fields in meta so in post_meta 2 X 3 = 6 records will be created but if I add the custom field in post table it will be a horizontal growth and only records will be created in post table only.
Also how wordpress query data from both the tables? Does it use some view or join query? Some people suggest adding custom fields in post_meta as array to minimize no. of records but how will filtering happen if data is stored as an array.

Drupal 7, listing users by custom field values

I created a custom field for a user's hometown, let's call it "field_home", that is required for every user when they register an account. They can only select certain text values from a list.
Is there any way I can add a "Hometown" column in admin/people, which lists every user's field_home value along with their user name and roles?
Thanks for any information!
I would recommend creating a new view. You can build a better view than the one provided in admin/people in no time.
Add your own custom fields, edit/cancel-account links and filtering criteria. That'd be much easier and faster.

Resources