Created
July 23, 2025 05:55
-
-
Save shameemreza/b8a80692c32bf632093de23d6fbcc541 to your computer and use it in GitHub Desktop.
Prevents WooCommerce from auto-completing subscription renewal orders that have $0 product value but include shipping costs. Forces these orders to remain in processing until manually completed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Prevent WooCommerce from auto-completing orders with $0 product total but shipping costs. | |
| * | |
| * @param bool $is_virtual Whether the order contains only virtual products. | |
| * @param WC_Order $order The order object. | |
| * @return bool | |
| */ | |
| function a8c_prevent_zero_value_order_completion( $is_virtual, $order ) { | |
| // Only modify behavior for subscription renewal orders | |
| if ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order ) ) { | |
| // Check if order has shipping costs | |
| if ( $order->get_shipping_total() > 0 ) { | |
| // Force non-virtual status to prevent auto-completion | |
| return false; | |
| } | |
| } | |
| return $is_virtual; | |
| } | |
| add_filter( 'woocommerce_order_is_download_only', 'a8c_prevent_zero_value_order_completion', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment