Hello,
I understand the variables are equal.
I’ve found this page that might help you out:
get_item_subtotal Examples
Let us know if this worked for you.
Thank you for your answer. I looked at the samples in the link you sent. However, I couldn’t find what I was looking for.
I hope you understand what I mean. I’m wondering if there is a function that does this. Otherwise unfortunately I’ll have to deal with it myself, work on it and write a new function.
There is a product named A.
Regular Price: $100 dollars
Sale Price: $50
The customer adds the product to the cart and successfully purchases the product.
This is where I start everything. I want to get regular price and sale price “on order”. So, I’m looking for questions like how much did the customer buy this product and bought it at a discount.
Yes, you can have this product-based information:
foreach ($order->get_items() as $item_id => $item ) {
$regular_price = $product->get_sale_price(); // The product raw sale price
$sale_price = $product->get_regular_price(); // The product raw regular price
}
But of course this is not true. Because, this price may change later. For example, the discounted price can be removed. That is, only regular price ($100) can be sold. Or a price of more: $110.
Hi there,
This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.
You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.
Cheers.
This is not a complex development issue. Unfortunately, you are copy-pasting canned answers. Previously, Woocommerce support was not like this.
I’m not asking you to write code. Such a function, usage etc. I’m asking whether there is or not.
I also wrote what you call complex. Maybe it helps someone else. I am sharing it below.
Have a nice day.
/**
* If there is a discounted item, save it in the woocommerce_order_itemmeta table for further use.
*
* @return void
*/
add_action( 'woocommerce_payment_complete', 'order_check_discounted_price_control' );
function order_check_discounted_price_control( $order_id ){
//create order object
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item_id => $item ) {
$product = $item->get_product();
//Check if the item is discounted
if($product->get_sale_price() != $product->get_regular_price()){
wc_add_order_item_meta($item_id,'_discounted_item', $product->get_regular_price());
}
}
Hi @loopforever,
Just so you know, the support staff here are not Woo developers and we help understand and troubleshoot WooCommerce’s built-in core features.
That said, here’s the list of functions in WooCommerce. You may take a look and find the one that helps achieve your goal.
https://woocommerce.github.io/code-reference/packages/WooCommerce-Functions.html
You might also be interested in reading the support policy of this forum:
https://woocommerce.com/support-policy/#customization
As mentioned above, I’ll leave this thread open in case anyone else wants to chime in.
Best regards.
Hi there,
We’ve not seen any activity on this thread for a while, so I’m marking it as resolved.
Hopefully, you were able to find a solution and the above resources for developers were helpful. If you have further questions, please feel free to open a new topic.
Thanks.