Change WooCommerce Order ID - woocommerce

I've recently migrated a website and during the migration process I received a couple of orders that didn't make it over. I entered the orders manually and tried to change the order ID through phpmyadmin by changing the Post ID, but when I did this it deleted the name and all the information from the order. Is there a proper way to change the order ID of an order?

Related

How to get WooCommerce cart id?

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.

Is it possible to pass a special query parameter value to a WooCommerce product link?

I am looking to use WooCommerce in a bit of a strange way, and I'm wondering if there is any way to make this possible. Here's my desired workflow:
Step #1: From a different site subdomain, provide a link to a certain virtual product, but with a query parameter with a unique user id number.
Explanation: The user is at othersite.example.com, and they get a link to buy a product in a WooCommerce store set up with a wordpress site at https://example.com/product/virtual-product
However, this product will be a payment to unlock something on the othersite.example.com site which has its own user and authentication system. (Firebase)
Would it be possible to pass a user id from the othersite.example.com by way of a url query parameter and then have that included in the order info?
ie. From the othersite.example.com someone could be given a link to the product like this https://example.com/product/virtual-product?userid=00000000000000000, with 00000000000000000 being their user id at othersite.example.com.
Then if that userid query value could be included in the order, the following steps should be doable.
Step #2: Have a webhook that fires when the product is purchased, telling a server managing the users for othersite.example.com that the user with userid 00000000000000000 has made a successful purchase of that product.
Is there a way to accept custom values like this to the order? Or is this totally out of the scope of WooCommerce's functionality?
Thanks so much.
I believe that it can be done by using a redirection/link directly to the checkout page, like: "http://yourdomain.com/checkout/?add-to-cart=PRODUCTID&000000" (tested)
In the example, "checkout" stands for the name of your checkout page, "PRODUCTID" stands for the id of desired product, "000000" stands for the user id of redirected person in the other website.
Then you can add a hidden input field to the checkout page (into checkout form, so you will see this value in order) and using the URL you can assign the "000000" (user id) to the value of this field.
I hope that works. If you have any problems with implementation, you can ask me.
- Useful link for hidden input field addition: https://stackoverflow.com/a/42614905/11003615
- Useful link for getting value from current URL using JS: https://web-design-weekly.com/snippets/get-url-with-javascript/
- Useful link for getting value from current URL using PHP/Wordpress Core: https://wordpress.stackexchange.com/questions/274569/how-to-get-url-of-current-page-displayed
- Useful link (contains 4 parts) for adding a custom field to checkout & validating this field & saving this field to order fields & displaying the value of this field in order page: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-7

How to unlink customers/users from WooCommerce orders

I had a failed customer/order import when I upgraded a WooCommerce site.
Customers are now logging in and seeing orders and customer information for random orders - not their own. It is a catastrophe!
I am thinking that a solution might be to unlink all customers from orders and forcing customers to be manually relinked on request.
Problem is - I have an unverified problem whereby one customer recreated a user and on login, had been "magically" linked to another customers order details - so even creating new users seems to be problematic.
Any suggestions would be helpful.
This is a possible explanation of your problem. The customer for an order is saved in the the wp_postmeta table with the meta_key '_customer_user'. This integer is a reference to 'ID' column of wp_users. I think your import broke this relationship. Did your import change user id's? If so you need to remap all the '_customer_user' meta_values to their corresponding new user ids.
If you want to just unlink orders from customers I would try setting this field to 0 or maybe to 1 which would mean that initial user (sysadmin) would now be the customer for all orders. If you do this remember to keep a record of the original '_customer_user' so you can try and recover the correct id later.

How to change the slug in Ghost to include only year and month?

In the latest release you have allowed us to add the date in the post slug. Is it possible to add only the year and the month? Even by editing the code? Because I'm trying to migrate from Wordpress I need it. In WP I use that format.
Note : I'm using Ghost 0.5
This is currently only possible to do in the database. You can change the value of the key permalinks in the settings table to read /:year/:month/:slug or run the following query on the database:
UPDATE settings SET value = '/:year/:month/:slug` WHERE key = 'permalinks'
In case you're using the default database (SQLite3) you can use a tool like SQLite Browser

Drupal Commerce order admin page, order id

I'm building a commerce site using Drupal Commerce. I've got it going very smoothly now but I've hit a dead end when I'm trying to create a module for handling shipping information and sending it to the shipping company for label printing.
The problem is, that I have created a new tab in an Order page,
admin/commerce/orders/order_id/printlabel
and I can access this page via a tab when I edit an order.
Now, I have no idea how I can pull the order_id number in the module. I have tried almost everything, entity_view, entity_metadata_wrapper, commerce_order.module API, but I have no idea how I can access the id and that is the key. When I get the ID, I can get the shipping information linked to it and I can send this data to the shipping company and save it.I also looked into the ways Commerce does things like combine Payment with Views but it seemed a bit too complicated for me to try so, I'm asking here. I can't get any answers on Drupal's own support forums.
Hope i got your question right.You created a custom menu admin/commerce/orders/*/printlabel where * is the order id of a particular order. You need the order id.
The simplest solution to it is getting it through the arguments or arg(). This is a function that drupal provides to get data from the arguments. For eg
if your url is www.xyz.com/admin/commerce/orders/0001/printlabel & you need order id i.e 0001 you can get it using arg(3).

Resources