Quantities not updating after refund on woocommerce - php

I have followed the instructions to refund products as per this link: https://docs.woocommerce.com/document/woocommerce-refunds/
On the email sent back to the customer, the order value has been updated and takes into consideration the refund, but the order quantity does not. The quantity stays the same.
How can I make sure I am pulling the correct order quantity? When My customers come to collect their goods their receipt still shows they are to receive the original quantity?
I know order quantities are stored in the table "woocommerce_order_item_meta" with a separate "order_item_id" for ordered quantity and refunded quantity, the latter signalled by an additional line: "_refunded_item_id". Do I need some code to sum the "_qty"'s?
I would like my customer emails and order reports to show the correct quantity, so happy to make just make changes to order-items.php and create a function to input into my report plugin (wp All export)

Actually, Woocommerce has no any default functionality to restore stock for cancelled and refunded orders.
There is one of the plugin to solve this solution. Woocommerce Auto Restore Stock is the plugin that will help you to achieve this.
It will automatically restore your WooCommerce inventory/stock for orders that were placed and refunded or canceled.
Hope this will work for you. Thanks.

Related

Generate another order number for same order if payment failed woocommerce

I'v been searching all over but it seem that this is a very spécifique question.
So we have a custom payment gateaway , and it dont accept duplicate order number.
Exemple : A customer try to buy a product woocommerce generate an order number for that product, information is transferred to payment gateway with that order number, if the customer fail the payment it will return with an error notice in the cart, but when the customers want to make the payment again from the cart the gateway don't accept it because the order number is duplicated (it has been processed in the first try). he need to delete that product from cart and add it again.
so my question is : how we can generate a new order number when the payment is failed?
thank you

WooCommerce Recalculate Order, Taxes - Delete & Add Order_item + discount

I would like to briefly give you some information about our problem here: We need to correct all our Woocommerce orders from 2021 and now we are facing a big challenge. Since we have changed the tax class on the products, we can't just have the order recalculated but need to re-add the entire order line item to the order and remove the old line item.
We have now found a workaround that works:
Edit corresponding purchase order
Set purchase order from "completed" to "on hold
Update/Save
Now the order can be edited:
Check which coupon has been redeemed
Remember the product ID of the order
Delete product completely
Add new product via product ID
If voucher was used Add voucher code
Update/Save
This is exactly the process we use to correct our orders as needed. From this we have programmed a bot that goes through this process in wp-admin. Unfortunately, with tens of thousands of orders, this takes months....
Now I have come across Hooks and Functions and believe there is a simpler solution here.
For example I found this thread: How Can I remove a particular product from an completed order in woocommerce?
foreach ($order->get_items() as $item_id => $item) {
if ($item_id == 3) {
wc_delete_order_item($item_id);
}
}
Here it is explained how to remove an order-item from the order.
We would need a Function that:
Opens an order
Saves the order_item_id to itself
Deletes the order_item
adds the order_item again
checks if there was a coupon
if yes: delete old voucher & add new voucher
Does anyone have any ideas or can help us with this?
Thanks a lot!

Backorders Purchase higher than stock

I have Prestashop 1.6. How do I manage this issue: Problem with backorders when a customer orders more items than are currently in stock ?.
Our store allows backorders. We have a problem where an item will show in stock, but if a customer orders more than the available quantity. he is not told until after the order has been placed and paid for.
I receive emails from customers who are upset because an item appears in stock when they add it to the cart, and when they view it in the cart. But immediately after payment is made, the order is placed in backorder
Example: we have 8 balls in stock customer places an order for 10 balls.
My idea is to display a message shipment in 4 days. But I don´t know how to do it.
I will appreciate your Help to find the solution
Regards
Not sure where you want to display that message but i might have a solution for you.
Go to prestashop\themes\yourTheme\templates\checkout_partials
open cart-detailed-product-line.tpl,
at the very bottom add:
{if {$product.stock_quantity} < {$product.cart_quantity}{l s='Warning: Quantity of product in your cart is out-of-stock and will take longer to be delivered.'}{/if}
If customer orders more than avaliable quantity they will see message like this in their cart right under the product:
How it works
Hopefully that helps!

Ecommerce database design, save product information without affecting historical data

What would be the best, if not, the practical way to design an e-commerce database wherein the product information of the product purchased by a customer should not update when the product information was updated?
To give a better understanding, here's a scenario:
Merchant created "Product A" where it is priced at $50.
Customer saw Product A and purchased it.
Customer visited the transaction history and viewed his recent purchase: Product A priced at $50
Month's after, Merchant updated the price of Product A to $80.
Customer viewed again his transaction history. His transaction with Product A should retain at $50 and not the updated price of $80 because it was the price he paid that time.
One solution I am looking into is to save the whole product information in a table as a PHP serialized data in "purchases.product_information".
Is it even a good idea to store PHP serialized data in a column? How's performance if a user wanted to search for a text in the product information like price, item name, etc.?
Any other workaround for this?
Thank you
It is a case of slowly changing dimensions (https://en.wikipedia.org/wiki/Slowly_changing_dimension)
A simple solution will be to have a separate table purchase_items and have all the columns that may change over time against each item (Example:price, discount etc) and purchase and purchase_items table will have one_to_many relationship
Although, there are more complex situations where the price of the product changes on the fly based on the time at which an order is made in a day etc. In these cases, the price may not be stored against the product itself
This answer is addresses exactly the issue and you might find this helpful
https://dba.stackexchange.com/questions/57992/ecommerce-orders-table-save-prices-or-use-an-audit-history-table

Getting product weight info in virtuemart inside order details/order history page

I have the following problem in virtuemart:
I have made a function to calculate shipping cost based on a five stage cost given by the shipping company. This works perfectly on the cart page, but on the order details and order history page it does not, as I cannot get the product weight in these pages.
I have looked into order_items.php where the order details references are kept, but there is no reference to the product weight, only to product id, quantity, category, etc.
Could anyone help me in how to get the product weight inside the order details page? I can do the rest in calculating the shipping rates and updating the final sales price, but I am stuck in getting this info.
Any help is welcomed :)
Try this,
I think you missed something about order tables, hope you are using VM2.x
In this version once the order is processed its payment,shipment information gets saved on the #__orders table.
In additionally the payment method Id and Shipment method Id also gets saved. So you can identify the method used on the order.
The idea of calculating ordered products shipping cost later on admin side is not practical bcoz later the shipping cost may very.
So practically once the user placed an order that time you have to save these information on the above table. If you're using VM default Shipping plugins they will do this by default.
Hope its clear.

Categories