WooCommerce get total of additional fees added to cart - woocommerce

Depending on the cart total, I add an additional fee to each order
$cart_fee = 6.64;
if ($cart_total > 0)
WC()->cart->add_fee(__('Shipping Insurance', 'txtdomain'), $cart_fee);
Now I need to get a total of those fees by date range by either an SQL query or a piece of code that would print these values out on a custom page.
I'm posting this question while researching but I am hoping I can get some ideas before it costs me hours of time.

Below are the two DB tables and their connections for you to start with.
Using the order_item_id, query to the item_meta table for getting the values.

Related

Woocommerce REST API - filter orders by number or date

I want to retrieve an order by its number (not order ID) or by a date.
Earlier I've tried to retrieve (with Postman) an order by its order_id, status or order_key - and it worked:
https://example.com/wp-json/wc/v1/orders?status=completed&consumer_key=ck_...&consumer_secret=cs_...
With the example above, it works correctly.
However, when I'm trying to use number, all of the orders are listed:
https://example.com/wp-json/wc/v1/orders?number=123&consumer_key=ck_...&consumer_secret=cs_...
I've tried also filter[number], the result is the same (all orders are listed):
https://example.com/wp-json/wc/v1/orders?filter[number]=123&consumer_key=ck_...&consumer_secret=cs_...
Question: Could you please explain how can I get order by order number (or a date) using Woocommerce REST API?
As per my understanding, you need to display orders in an ASC or DESC order based on the order number.
you can use orderby and order query string parameter like this to get the order by date https://localhost/wp-test/wp-json/wc/v3/orders?&orderby=date&order=asc&consumer_key=ck_b9f70548c7b676&consumer_secret=cs_10acfa5ab943eb6a0e
Generally order by date will provide you the result of an order by number too because the order placed on the latest date will have the latest order id as per WordPress until you modify from the admin side and vice-versa
Please let me know if I can help you further..

Insert Discount - Coupon with SQL in NopCommerce

I do use nopCommerce 3.9 and I would like to insert coupon code from my C# program code. There are requirements such as "Has shopping cart amount" and "Blocked on product". The insert is working fine, I can see the inserted records and I think there are logically right. (The same process happening if I create Discount from Nop admin panel.)When I open the inserted coupon from Nop admin the "Discount info" tab is perfect, on the "Requirements" tab I see the requirements "Requirement Customer has x.xx amount in their shopping cart" and the "Requirement Block Discount on Product", but without value. If I modify the shopping cart value only (I don't modify the "blocked products" on purpose) and save it and reload the page, than everything is good. The blocked products are appeared too.
When I check the data tables I don't see any changes there. The records are the same as I inserted. I guess there is another table(s), where I have to update something, but I cannot find which one it is.
I would appreciate for any help.
From the comments, I believe OP want to insert the new discount rule with two things:
Cart has minimum total X.
Cart has specific product(s) Y.
And the issue is,
Its working properly if they apply discount rule from admin panel,
however, applying it programmatically couldn't store specific
products on a single call.
There are different tables for discount in nopCommerce.
Discount - main table
DiscountRequirement - stores requirement information
Discount_AppliedToProducts - stores discounted products information
Creating a discount rule first time will add entry in discount table only. Then the id of discount table will be used for reference to the DiscountRequirement and Discount_AppliedToProducts table.
It was everything good with my process. The issue was the nopCommerce cache. The nopCommerce keeps the discounts in cache. After I clear the cache I can see my values.
Thanks for everyone who tried to help or had a thought!

WooCommerce - Change customer order after it has been placed and paid

Using three plugins:
WooCommerce
Subscriptio
WooEvents
I have created a product which allows for a customer to pay for an event over five instalments.
A customer has placed an order and made their first of the five payments via PayPal and has then contacted me to advise they have booked the wrong event.
The correct event is exactly the same except the dates are a month sooner.
I have added the following snippet to be able to edit 'processing' orders:
add_filter( 'wc_order_is_editable', 'wc_make_processing_orders_editable', 10, 2 );
function wc_make_processing_orders_editable( $is_editable, $order ) {
if ( $order->get_status() == 'processing' ) {
$is_editable = true;
}
return $is_editable;
}
From the order screen within the back-end of WordPress I can see that the the order can be edit by way of removing the product from the order or editing the meta data and cost.
The correct product that should have been ordered has a different product/variation ID.
My question is simply:
Should I remove the incorrectly ordered product from the order and add the correct product (both have the same properties with the exception of the courses dates); or
Should I just change the meta data and increase the stock levels for the incorrectly product back to X and reduce the stock level for the correct product?
Your second option is much better. Change the meta from database if its accessible and then manage the stock accordingly.
I have not yet done this, but according to this exchange ...
How can I add a product to an existing and paid Woocommerce order?
... you can set the order status to "On Hold" and make changes to the order itself. I presume you would then return the status to "Processing".
I would expect that if the application permits those changes, then it would be doing the background meta changes to inventory levels, etc., and spare you the problem of doing so (and the potential errors that may occur when messing with the data tables outside of the application).
Like I said, I haven't done this. But it might be worthwhile doing a little test to make sure it works as it seems to be described in the answer to the other question.
J

Custom loop for getting products flagged as new

I was looking for a way to build a custom loop to get the products flagged with the "new" label.
I could use the sort from the insert time, but that would always include a certain number of products, my goal here is to get those products that conform to the WooCommerce setting that says the product is considered new for a given number of days.
i have a free plugin - WooCommerce Product Badge, it has your requested feature to display "New" label with certain days defined.

Access Report - Can't add a sum for a calculated currency column

I've generated a simple access report that is used for purchasing.
Basically, there are two tables, one for purchase orders, and one for the items on the purchase orders.
For the items on an order, I store the item details, quantity ordered, quantity delivered, and price per unit. (plus a few other fields which aren't relevant in the context of this question).
I'm generating a report to list all outstanding items still on order, and the report has a calculated field showing the outstanding quantity * cost per item. This works perfectly fine.
What I'm struggling with, is showing a sum of this calculated field (i.e. a total cost of all outstanding items), but when I try to add a total to the column, it only gives me the option of adding an item count for the column. The column is a 'Currency' field.
What might I be doing wrong, or am I expecting too much from access?
Resolved. I created the only option that the GUI would allow (item count), then modified the query from:
=Count(*)
to
=Sum([Quantity]*[Cost])
Works perfectly.

Resources