Created
August 7, 2026 08:50
-
-
Save esedic/ddc0a838ec8490795062d6647c952f78 to your computer and use it in GitHub Desktop.
Samodejno zaključi brezplačna digitalna naročila (0,00 €). Deluje samo za naročila, ki vsebujejo izključno virtualne/prenosljive izdelke.
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
| /** | |
| * Samodejno zaključi brezplačna digitalna naročila (0,00 €). | |
| * Deluje samo za naročila, ki vsebujejo izključno virtualne/prenosljive izdelke. | |
| */ | |
| add_filter( 'woocommerce_payment_complete_order_status', 'auto_complete_free_digital_orders', 10, 3 ); | |
| function auto_complete_free_digital_orders( $status, $order_id, $order ) { | |
| // Varnostna preverba | |
| if ( ! $order instanceof WC_Order ) { | |
| return $status; | |
| } | |
| // Naročilo mora biti brezplačno | |
| if ( (float) $order->get_total() !== 0.0 ) { | |
| return $status; | |
| } | |
| // Preveri, da so vsi izdelki virtualni ali prenosljivi | |
| foreach ( $order->get_items() as $item ) { | |
| $product = $item->get_product(); | |
| if ( ! $product ) { | |
| continue; | |
| } | |
| if ( ! $product->is_virtual() && ! $product->is_downloadable() ) { | |
| return $status; | |
| } | |
| } | |
| // Samodejno nastavi status na completed | |
| return 'completed'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment