


How to Automate WooCommerce Order Completion for Specific Payment Methods?
Autocompletion of Paid Orders in WooCommerce for Specific Payment Methods
WooCommerce generally autocompletes orders for virtual products. However, certain payment methods, such as "Bank wire," "Cash on delivery," and "Cheque," require a conditional approach.
woocommerce_payment_complete_order_status Filter Hook
The optimal solution for this issue is to leverage the woocommerce_payment_complete_order_status filter hook, which is used by all payment methods when a payment is required at checkout.
Conditional Code Using the Filter Hook
The following code utilizes the filter hook and conditionally applies the status change based on payment method:
add_filter('woocommerce_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3); function wc_auto_complete_paid_order($status, $order_id, $order) { // Check if the payment method is not "Bank wire," "Cash on delivery," or "Cheque." if (!in_array($order->get_payment_method(), array('bacs', 'cod', 'cheque'))) { // If not, change the order status to "completed." return 'completed'; } // Otherwise, do not modify the order status. return $status; }
By using this filter hook, you can effectively and accurately update the status of paid orders based on payment methods without triggering multiple notifications to customers.
Alternatives
Code Snippet:
If the payment methods you want to target are limited to those that do not trigger auto-completion by default ("Bank wire," "Cash on delivery," and "Cheque"), you can use the following code:
add_action('woocommerce_thankyou', 'custom_woocommerce_auto_complete_paid_order', 10, 1); function custom_woocommerce_auto_complete_paid_order($order_id) { $order = wc_get_order($order_id); // Check if the payment method is not "Bank wire," "Cash on delivery," or "Cheque." if (!in_array($order->get_payment_method(), array('bacs', 'cod', 'cheque'))) { // If not, update the order status to "completed." $order->update_status('completed'); } }
Plugin:
The "WooCommerce Autocomplete Orders" plugin can also provide a solution for specific payment methods. However, it may not work with certain Credit Card gateways.
The above is the detailed content of How to Automate WooCommerce Order Completion for Specific Payment Methods?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
