Skip to content
Advertisement

Hook woocommerce price in backend order edition

I need to change item product prices in Woocommerce Backend Order. I tried tu use the following hook, but I have a problem trying to obtain the order id. Any suggestion? Thanks in advance!

JavaScript

Complete problem:

The complete problem is as follows. I am using a plugin that adds a field to the product called wholesale price. If the customer has the wholesale customer role, the order uses those prices. The plugin works fine, but it does not take the price in the backend. I talked to the author and it’s something they do not plan to change yet. My client needs to modify the orders. But when it enters the backend, it takes the common price, not the wholesaler. I need to do something in the backend that allows me to detect if the order is from a client with a wholesale customer role. If yes, take the correct price when adding products. There is more information on the discussion with the author here. https://wordpress.org/support/topic/wholesale-prices-in-backend-editing-orders/ Thank you very much for the help you can give me.

Options:

woocommerce_get_price: does not work because I cannot obtain the customer id

woocommerce_ajax_add_order_item_meta: nice option, but I could not find a sample

Button: nice option, but I do not know how can I change the price. I tryed the follow:

JavaScript

Advertisement

Answer

Updated

The hook that you are using is not for orders, but only for products, and is made to change the displayed prices only. So you will not get the order ID with it.

You could change the price display in many hooks, but if you want to change order item prices for real (not only the displayed formatted prices), you should trigger this prices changes when order is updated for example.

In this case you can use a custom function hooked in save_post action hook:

JavaScript

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested and and finally works.

I have added a security to avoid the order items to be updated twice.

The method $order->calculate_totals(); slow down the process a little bit… It’s normal as it will calculate totals, update data and refresh caches.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement