juanmdp
asked 7 years ago

Greetings,
As a requirement for a store, we had to add a functionality to reproduce an order to test it if some kind of numbers wouldn’t add up at checkout. In short, given an order ID we populate a cart with the items of an order.
One thing that was noted to us is that items change price over time so this population of the cart should be with its original price. And that’s where my troubles began.
The only hook I could find for that purpose is woocommerce_before_calculate_totals ; in there, since it’s an older version of Woocommerce (2.8 I think? And no, upgrading I’m afraid isn’t an option for the time being) I did the following:
foreach ( $cart_object->cart_contents as $cart_item_key => &$item ) {
$originalprice = $_COOKIE[“originalprice”];
$item[‘data’]->price = $originalprice;
}
a dump of the cart after adding all items programmatically shows me that the items were put in the cart with the right prices (the original one). However, as soon as I go to the checkout, the prices are the current ones. Furthermore, on the page where I do this process of entering an order ID and populating the cart I did a dump of the cart just when visiting the page and it shows the items with their current price as opposed to the original one I assigned through the hook.
At this point I’m at a loss on how to achieve this, I’ve read plenty of topics but they all conclude this is the only way. I’m also at a loss as to why it does it right after the post but reverts to the current price as soon as I visit any other page. Any kind of tip or insight will be greatly appreciated.

1 Answers
DominicStaff
answered 7 years ago

At the moment, we can not support you while using another our product. If you want to have it, we are ready to help you as a custom work with a charge of fee ( about $100/h). 
In case that you are still interested in the feature, please kindly let us know, we will check and estimate the time.

Powered by DW Question & Answer Pro