I used artificial intelligence for the first time
But the code you told me is not working
To convert veins automatically from treatment to complete after 30 seconds
Only on virtual products
There are two specific payment methods
But it doesn’t work
// Add a 30 second delay for virtual products
add_filter( 'woocommerce_payment_complete_order_status', 'wc_delay_virtual_order', 10, 2 );
function wc_delay_virtual_order( $order_status, $order ) {
if ( $order->has_downloadable_item() && ! $order->has_status( 'completed' ) ) {
return 'on-hold'; // change to any other status you wish to use.
}
return $order_status;
}
add_action( 'woocommerce_thankyou', 'wc_delay_virtual', 30 );
function wc_delay_virtual( $orderid ) {
// Get the order object and check for downloadable items.
$order = new WCOrder($orderid);
if ( $order->hasDownloadableItem() ) {
// Set a 30 second delay for virtual products.
sleep(30);
// Update the order status to complete.
$order->updateStatus('completed');
}
}
// Add a custom payment gateway for MobileWallet and Reference Code payments.
add-filter('woocommerce-payment-gateways','wc-add-mobilewallet-referencecode');
function wc-add-mobilewallet-referencecode($methods){
$methods[] = 'WCMobileWallet'; // MobileWallet payment gateway class name.
$methods[] = 'WCReferenceCode'; // Reference Code payment gateway class name.
return $methods;
}
I tried to add this code inside plugin and inside function.php
I am waiting for your response to solve my problem, thank you
2
Answers
The part of your code posted below has an issue. you cant use
-
in between function name likewc-add-mobilewallet-referencecode
instead it should bewc_add_mobilewallet_referencecode
using and underscore "_"Your correct code should look so:
And since you just need to change order status to complete on downloadable product, just need the code below:
The requirement doesn’t seem to work for the following reasons:
Payment gateways will have their configuration where after each successful order, the status will be updated based on the configuration.
Making the customer wait 30 seconds on the browser is not recommended.
Even if you forcefully update the order status on the thankyou page hook, what will happen next is if the woocommerce or any third-party plugin or payment plugin has different order statuses, those will be updated as soon as your update is done.
Nevertheless, there are three possible ways for your requirement.
Search for payment configuration and update the order completion status there. For example, in the case of Novalnet Payment Gateway, I use their configuration, so I need not do anything here.
On the WooCommerce shop backend, you have the settings you can use it. Refer https://woocommerce.com/document/woocommerce-order-status-control/
Based on your business logic, you can set up a cron to update all the virtual orders that aren’t on complete order status. Refer https://developer.wordpress.org/plugins/cron/