This question already has answers here:
Automark ONLY Paid orders to "Completed" status in WooCommerce 3+
(1 answer)
WooCommerce: Auto complete paid orders
(5 answers)
Set WooCommerce order status when order is created from processing to pending
(4 answers)
Closed 10 months ago.
This post was edited and submitted for review 10 months ago and failed to reopen the post:
Original close reason(s) were not resolved
I am trying to auto complete order statuses for orders whose status is either pending or on hold. but the function is not working
add_filter( 'woocommerce_payment_complete_order_status', 'test_wc_autocomplete_paid_orders' );
function test_wc_autocomplete_paid_orders( $order_status, $order_id ) {
$order = wc_get_order( $order_id );
if ( $order_status == 'processing' && ( $order->status == 'on-hold' || $order->status == 'pending') ) {
return 'completed';
}
return $order_status;
}
it is for payment through banks through stripe.
I tried woocommerce_thankyou action also. but still not working.
what I am doing wrong? it is for stripe sofort transfer.
thanks
Related
This question already has answers here:
Change COD default order status to "On Hold" instead of "Processing" in Woocommerce
(3 answers)
Change default WooCommerce order status to processing for cheque and bacs payments
(2 answers)
Closed last year.
I would like to ask.
Is there any way I can automatically make every new Woocommerce order’s status on hold?
Paypal and Visa card payments is getting automatically “processing” status but I don’t want that. I would like all my new orders getting order status “On Hold” and getting on hold email
I have found the following code which I add it on function child theme and is working fine but there is a small problem.
The customer still getting proccessing status email instead of getting “On hold” email.
/**
* Auto On hold all WooCommerce orders.
*/
function custom_woocommerce_auto_complete_order( $order_id ) {
if ( ! $order_id ) {
return;
}
$order = wc_get_order( $order_id );
if( 'processing'== $order->get_status() ) {
$order->update_status( 'on-hold' );
}
}
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
Is there anyway that I can edit this code and customer get the “On hold” email instead of processing email?
Please let me know if someone can help me.
Thank You!
I'm building a ticketing website for events. I'm using WooCommerce and The Events Calendar plugin.
I've already made it so that users must be logged in to buy a ticket (product).
Then I found this code snippet that would limit it so that only 1 product can be purchased per order
add_filter( 'woocommerce_add_to_cart_validation', 'wc_limit_one_per_order', 10, 2 );
function wc_limit_one_per_order( $passed_validation, $product_id ) {
if ( 31 !== $product_id ) {
return $passed_validation;
}
if ( WC()->cart->get_cart_contents_count() >= 1 ) {
wc_add_notice( __( 'This product cannot be purchased with other products. Please, empty your cart first and then add it again.', 'woocommerce' ), 'error' );
return false;
}
return $passed_validation;
}
This would work, but in the first if statement you can see that the product ID has to be specified. I know I can also change this to an array like if ( ! in_array( $product_id, array( 31, 32, 33 ) ) ) { but the problem is that I would need to keep updating the IDs for every new event. Is there a way to do this so it applies to all products all the time? If not with code then maybe with settings or a plugin?
I also need to prevent customers (users) from returning to the site later and buying another ticket. So, I need to limit specific products so that only 1 of that SKU can be purchased per user account forever, meaning they can't just return to the site and start the buying process again. Is there a way to do this?
Many thanks in advance.
Is there a way to do this so it applies to all products all the time?
Sure. Just force the Cart to empty before adding a new item:
add_filter( 'woocommerce_add_to_cart_validation', 'bbloomer_only_one_in_cart', 9999, 2 );
function bbloomer_only_one_in_cart( $passed, $added_product_id ) {
wc_empty_cart();
return $passed;
}
Source and screenshot: https://www.businessbloomer.com/woocommerce-allow-1-product-cart/
I need to limit specific products so that only 1 of that SKU can be
purchased per user account forever, meaning they can't just return to
the site and start the buying process again
As #7uc1f3r said, please share the code you tried with and then we'll take a look
Is there any way to automatically update the order status of all the "Order Placed" to "Processing" after 2 days. Currently, this can be done manually from Woocommerce < Orders < Change order status.
For example - If a user placed an order it should automatically change status to processing after 2 days.
I've tried this plugin name WunderAutomation, but unable to get the result.
Plugin link - https://wordpress.org/plugins/wunderautomation/
Is there any WooCommerce expert out there who can share a code to change order status automatically?
Thanks for your help
Create a WordPress Cron for two days.
add_filter( 'cron_schedules', 'example_add_cron_interval' );
function example_add_cron_interval( $schedules ) {
$schedules['two_days'] = array(
'interval' => 172800,
'display' => esc_html__( 'Every Two Days' ), );
return $schedules;
}
Create a hook for your function.
add_action( 'bl_cron_hook', 'bl_cron_exec' );
Schedule the hook using the WP Cron we setup above.
if ( ! wp_next_scheduled( 'bl_cron_hook' ) ) {
wp_schedule_event( time(), 'two_days', 'bl_cron_hook' );
}
Create the function that is called in your hook.
function bl_cron_exec() {
// Get list of WC orders.
// Loop over each order.
// Check if order is over two days old
// If older then two days then set status of order.
}
WordPress Cron examples taken from WordPress Cron Handbook. You might want to look at the WC_Order documentation to see how to update an orders status.
This is completely not tested and will need to be adjusted based on specific needs. I don't use WordPress Cron very often, so there might be a thing or two I'm missing.
On a Wordpress-Shop I use WooCommerce (WC) with Advenced-Custom-Fields (ACF)
and WP-All-Import (WPAI) + WP-All-Export (WPAE).
I added a ACF field CustomerNumber to the WC-Customer (which enhanced the WP-User).
On the WPAI-XML-Import I set the CustomerNumber with a value from a ERP.
So all customers have a unique CustomerNumber.
I now need to export the WC-Orders (to import them in the ERP again).
The Order-XML must include the CustomerNumber from the Customer belongs to the Order.
As I see, the other standard fields from the customer – like name and address – are copied automatically to the order (by WooCommerce itself).
My question is now: How I have to do this for the ACF’s?
Did I have to do this by code on my own? Adding the same AC-fields to the WC-Order and hook into the order checkout and copy the values from the customer to the order?
Or is there some kind of setup which do that and which I did not recognize?
Thx
I did not really found an answer.
My current solution is now as I described it in my question.
I added a new rule for these acf to also make them available on the orders.
Then I added a hook to new created orders, determine the acf from the user and copied the necessary values into the order acf.
function di_woocommerce_new_order( $order_id ) {
$order = new WC_Order( $order_id );
if ( !$order ) return;
$customer_id = $order->get_customer_id();
if ( !$customer_id ) return;
$customer = new WC_Customer($customer_id);
if ( !$customer ) return;
$customer_number = $customer->get_meta('customernumber');
if ( !$customer_number ) return;
// add customer number
$order->add_meta_data('customernumber', $customer_number);
// update order modified timestamp
$order->add_meta_data('order_last_updated', current_time( 'mysql' ));
$order->save_meta_data();
}
add_action( 'woocommerce_checkout_order_processed', 'di_woocommerce_new_order', 10, 1);
I am iterating through all subscription products that appear because of [products] shortcode and I want to do a task if the subscription product has n number of trial period days. How can I get this information?
Try this one.
if ( class_exists( 'WC_Subscriptions_Product' ) &&
WC_Subscriptions_Product::get_trial_length( $product_id ) > 0 ) {
//do a thing here
}
Reference:
WC_Subscriptions_Product