Woocommerce get total (no cart) [duplicate] - woocommerce

This question already has answers here:
Get order totals by order id without Formatting in WooCommerce
(2 answers)
How to get WooCommerce order details
(6 answers)
Closed 9 months ago.
I have this code:
$amount = $woocommerce->cart->total;
if ((! $option['amount_min'] || $amount >= $option['amount_min']) && (! $option['amount_max'] || $amount <= $option['amount_max'])) {
This works fine when in cart.
=> How to make it work for manually (admin) created orders with a payment link? So there is technically no cart.

Related

SQLite unsure about ALL syntax [duplicate]

This question already has answers here:
SQLite syntax for "ALL"
(3 answers)
Closed last month.
I'm trying to find out which customer spent the most on orders, in addition to how much they have spent in total.
This is my current code. However, im getting a syntax error near ALL
SELECT c.id, sum(i.Quantity * p.UnitPrice) AS TotalSpend
FROM Customers c, Orders o, OrderItems i, Products p
WHERE c.id = o.CustomerID
AND o.id = i.OrderID
AND i.ProductID = p.id
AND sum(i.Quantity * p.UnitPrice) > ALL(
SELECT sum(i.Quantity * p.UnitPrice)
FROM OrderItems i, Products p
WHERE i.ProductID = p.id)
Not too sure where i have committed the syntax error
Apparently the keyword ALL is not supported by SQLite.

How to exclude product for coupon use [duplicate]

This question already has an answer here:
Create a coupon programmatically since WooCommerce 3+
(1 answer)
Closed 3 months ago.
I am creating a custom coupon and trying to exclude products to use that specific coupon but when i am adding products id in that code its only adding 1 product in the exclude not others.
$permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$bemail= 'email#gmail.com';
$coupon = new WC_Coupon();
$coupon->set_code( substr(str_shuffle($permitted_chars), 0, 16) . '5489' );
$coupon->set_amount(5489);
$coupon->set_excluded_product_ids(1393,1324);
$coupon->set_email_restrictions($bemail);
$coupon->save();
try to pass an array of product ids in set_excluded_product_ids().
example:-
$pids = array(101, 102, 103);
$coupon->set_excluded_product_ids($pids);
Reference:- https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-coupon.php#L622

Get WooCommerce Total Sales Dollar Amount (revenue) [duplicate]

This question already has answers here:
Get orders total purchases amount for the day in Woocommerce
(2 answers)
Closed 4 years ago.
Is there anyway to get WooCommerce total sales dollar amount, I'm using this plugin and it's shortcode for this purpose but I'm looking for a way to get the today's total revenue amount (gross sales) without using a plugin. I'm gonna use that code inside another plugin that I'm developing.
Try this below code
$Select_Order_Details = $wpdb->get_results( "SELECT SUM(meta.meta_value) AS total_sales, COUNT(posts.ID) AS total_orders FROM wp_posts AS posts
LEFT JOIN wp_postmeta AS meta ON posts.ID = meta.post_id
WHERE meta.meta_key = '_order_total'
AND posts.post_type = 'shop_order'
AND posts.post_status IN ( '" . implode( "','", array( 'wc-completed', 'wc-processing', 'wc-on-hold' ) ) . "' )");
$Select_Order_Details = json_decode(json_encode($Select_Order_Details),true);
print_r($Select_Order_Details);exit;

woocommerce booking subtract weeks or days from date picked

I am using Woothemes Woocommerce Bookings. I want users to be able to enter a date in the product booking date picker and have the system make the booking three weeks prior to that date.
e.g. customer uses the date picker to select 28/04/2018 (28th April 2018) but the booking is made for 07/04/2018 (7th April 2018).
All bookings are made in blocks of 5 weeks (35 days) but they enter in a date that results in their booking being 3 weeks (21 days) before that date, and 2 weeks (14 days) after. Customers only select one date, there is no start and end date for them to select.
The documentation references a hook called woocommerce_new_booking that you can use in order to modify the booking date before it's saved to the database. This code will modify the booking start and end date to 3 weeks prior to the date they select. Add this code to your functions.php file.
add_action( 'woocommerce_new_booking', 'modify_woocommerce_booking_date');
function modify_woocommerce_booking_date( $booking_id ) {
$booking = new WC_Booking( $booking_id );
$booking_start = $booking->get_start();
$booking_end = $booking->get_end();
$new_booking_start = strtotime ( '-3 week' , $booking_start ) ;
$new_booking_end = strtotime ( '-3 week' , $booking_end ) ;
$booking->set_start( $new_booking_start );
$booking->set_end($new_booking_end);
$booking->save();
}

Add multiple columns in custom WordPress table if it does not exist [duplicate]

This question already has answers here:
Add new column to wordpress database
(7 answers)
Closed 7 years ago.
I make a plug-in in word press and create some tables, during upgrading the plug-in i need to add columns to existing table, i want to add columns to table if they are not exist in the table.How can i do so ?
you can simply use this query (change the table name and column name)
$row = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'wp_customer_say' AND column_name = 'say_state'" );
if(empty($row)){
$wpdb->query("ALTER TABLE wp_customer_say ADD say_state INT(1) NOT NULL DEFAULT 1");
}

Resources